a.txt 3.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. <!-- 黑色日期卡片 -->
  2. <div class="mb-4 wyoj-date-card" id="wyoj-date-card"
  3. style="position:relative;overflow:hidden;background:#000;color:#fff;padding:2rem 1.5rem;border-radius:0;text-shadow:0 1px 3px rgba(0,0,0,0.75);">
  4. <!-- 随机方格背景层 -->
  5. <div id="wyoj-date-grid"
  6. style="position:absolute;top:0;left:0;right:0;bottom:0;display:grid;z-index:0;pointer-events:none;"></div>
  7. <!-- 内容层 -->
  8. <div style="position:relative;z-index:1;">
  9. <div class="d-flex justify-content-center align-items-center">
  10. <div style="writing-mode:vertical-rl;font-size:1.5rem;font-weight:bold;letter-spacing:0.3em;line-height:1;">
  11. <?= $monthText ?>
  12. </div>
  13. <div class="mx-4" style="font-size:5rem;font-weight:900;line-height:1;">
  14. <?= $dayNum ?>
  15. </div>
  16. <div style="writing-mode:vertical-rl;font-size:1.5rem;font-weight:bold;letter-spacing:0.3em;line-height:1;">
  17. <?= $weekText ?>
  18. </div>
  19. </div>
  20. <div class="text-center mt-4" style="font-size:1rem;letter-spacing:0.05em;">
  21. <?php if ($daysLeft > 0): ?>
  22. 距 <strong>NOIP2026</strong> 还有 <strong><?= $daysLeft ?></strong> 天
  23. <?php elseif ($daysLeft === 0): ?>
  24. <strong>NOIP2026</strong> 就是今天!
  25. <?php else: ?>
  26. <strong>NOIP2026</strong> 已结束
  27. <?php endif; ?>
  28. <div class="mt-2" style="font-size:0.9rem;opacity:0.85;">
  29. <strong>CSP-J/S 2026</strong> 第一轮 9 月 19 日 · 第二轮 10 月 31 日
  30. </div>
  31. </div>
  32. </div>
  33. </div>
  34. <script>
  35. (function () {
  36. var card = document.getElementById('wyoj-date-card');
  37. var grid = document.getElementById('wyoj-date-grid');
  38. if (!card || !grid) return;
  39. // ===== 可调参数 =====
  40. var COLORS = ['#0a0a0a', '#1f1f1f', '#333333', '#4a4a4a', '#666666']; // 5 档灰→黑
  41. var CELL = 22; // 每个小方格的边长(px)
  42. var P = 0.08; // 每格每秒变色的概率(0~1),越大越跳
  43. // ====================
  44. var cells = [];
  45. var lastCols = 0, lastRows = 0;
  46. function pickColor() {
  47. return COLORS[Math.floor(Math.random() * COLORS.length)];
  48. }
  49. function build(force) {
  50. var w = card.clientWidth;
  51. var h = card.clientHeight;
  52. var cols = Math.max(1, Math.ceil(w / CELL));
  53. var rows = Math.max(1, Math.ceil(h / CELL));
  54. if (!force && cols === lastCols && rows === lastRows) return;
  55. lastCols = cols;
  56. lastRows = rows;
  57. grid.style.gridTemplateColumns = 'repeat(' + cols + ', 1fr)';
  58. grid.style.gridTemplateRows = 'repeat(' + rows + ', 1fr)';
  59. grid.innerHTML = '';
  60. cells = [];
  61. for (var i = 0; i < cols * rows; i++) {
  62. var d = document.createElement('div');
  63. d.style.backgroundColor = pickColor();
  64. // 每格单独的过渡时长,让变化错开,不会整片一起闪
  65. d.style.transition = 'background-color ' + (0.5 + Math.random() * 0.5).toFixed(2) + 's ease';
  66. grid.appendChild(d);
  67. cells.push(d);
  68. }
  69. }
  70. build(true);
  71. // 尺寸变化时重建(只在行列数变化时真的重建,避免无谓重置)
  72. if (window.ResizeObserver) {
  73. new ResizeObserver(function () { build(false); }).observe(card);
  74. } else {
  75. window.addEventListener('resize', function () { build(false); });
  76. }
  77. // 每秒给每格一个 p 的变色机会
  78. setInterval(function () {
  79. for (var i = 0; i < cells.length; i++) {
  80. if (Math.random() < P) {
  81. cells[i].style.backgroundColor = pickColor();
  82. }
  83. }
  84. }, 1000);
  85. })();
  86. </script>