HTML+CSS实现2026年春节倒计时!!附源码!!

12 0

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?立即注册

×

源码如下:
  1. <!DOCTYPE html>
  2. <html lang="zh-CN">
  3. <head>
  4.     <meta charset="UTF-8">
  5.     <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6.     <title>2026年春节倒计时 | 春节倒计时网站</title>
  7.     <meta name="description" content="2026年春节倒计时网站,实时显示距离2026年2月17日春节的时间,支持多种主题切换,包含福字烟花效果。">
  8.     <meta name="keywords" content="2026春节,春节倒计时,春节,倒计时,2026年,福字烟花,春节主题,2月17日">
  9.     <meta name="author" content="laddzhao">
  10.     <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
  11.     <link rel="icon" href="assets/images/favicon.ico" type="image/x-icon">
  12.     <style>
  13.         :root {
  14.             --primary-color: #d32f2f;
  15.             --secondary-color: #ff9800;
  16.             --background-color: #fef5f5;
  17.             --text-color: #333;
  18.             --accent-color: #ffeb3b;
  19.             --panel-color: #fff;
  20.             --shadow-color: rgba(0, 0, 0, 0.1);
  21.             --font-family: 'Microsoft YaHei', 'Segoe UI', sans-serif;
  22.         }

  23.         * {
  24.             margin: 0;
  25.             padding: 0;
  26.             box-sizing: border-box;
  27.         }

  28.         body {
  29.             font-family: var(--font-family);
  30.             background-color: var(--background-color);
  31.             color: var(--text-color);
  32.             min-height: 100vh;
  33.             overflow-x: hidden;
  34.             transition: all 0.5s ease;
  35.         }

  36.         .container {
  37.             max-width: 1200px;
  38.             margin: 0 auto;
  39.             padding: 20px;
  40.             position: relative;
  41.             z-index: 1;
  42.         }

  43.         header {
  44.             text-align: center;
  45.             padding: 30px 0;
  46.             position: relative;
  47.         }

  48.         h1 {
  49.             font-size: 3.5rem;
  50.             color: var(--primary-color);
  51.             margin-bottom: 10px;
  52.             text-shadow: 3px 3px 0 var(--shadow-color);
  53.             letter-spacing: 2px;
  54.         }

  55.         .subtitle {
  56.             font-size: 1.3rem;
  57.             color: var(--secondary-color);
  58.             margin-bottom: 30px;
  59.             font-weight: 500;
  60.         }

  61.         .theme-selector {
  62.             display: flex;
  63.             justify-content: center;
  64.             flex-wrap: wrap;
  65.             gap: 15px;
  66.             margin: 30px 0;
  67.         }

  68.         .theme-btn {
  69.             padding: 10px 20px;
  70.             border: none;
  71.             border-radius: 30px;
  72.             font-family: inherit;
  73.             font-weight: 600;
  74.             cursor: pointer;
  75.             transition: all 0.3s ease;
  76.             box-shadow: 0 4px 8px var(--shadow-color);
  77.             display: flex;
  78.             align-items: center;
  79.             gap: 8px;
  80.         }

  81.         .theme-btn:hover {
  82.             transform: translateY(-3px);
  83.             box-shadow: 0 6px 12px var(--shadow-color);
  84.         }

  85.         .theme-btn.active {
  86.             transform: scale(1.05);
  87.             box-shadow: 0 0 15px var(--accent-color);
  88.         }

  89.         .countdown-container {
  90.             background-color: var(--panel-color);
  91.             border-radius: 20px;
  92.             padding: 40px 30px;
  93.             box-shadow: 0 15px 35px var(--shadow-color);
  94.             margin: 30px auto;
  95.             max-width: 900px;
  96.             position: relative;
  97.             overflow: hidden;
  98.             border: 2px solid var(--primary-color);
  99.         }

  100.         .countdown-title {
  101.             text-align: center;
  102.             font-size: 2.2rem;
  103.             margin-bottom: 30px;
  104.             color: var(--primary-color);
  105.             display: flex;
  106.             align-items: center;
  107.             justify-content: center;
  108.             gap: 15px;
  109.         }

  110.         .countdown {
  111.             display: flex;
  112.             justify-content: center;
  113.             flex-wrap: wrap;
  114.             gap: 25px;
  115.             margin: 40px 0;
  116.         }

  117.         .countdown-item {
  118.             display: flex;
  119.             flex-direction: column;
  120.             align-items: center;
  121.             background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
  122.             color: white;
  123.             padding: 25px 20px;
  124.             border-radius: 15px;
  125.             min-width: 150px;
  126.             box-shadow: 0 8px 20px rgba(0, 0, 0, 0.2);
  127.         }

  128.         .countdown-value {
  129.             font-size: 4.5rem;
  130.             font-weight: 800;
  131.             line-height: 1;
  132.             text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.3);
  133.         }

  134.         .countdown-label {
  135.             font-size: 1.3rem;
  136.             margin-top: 10px;
  137.             letter-spacing: 1px;
  138.         }

  139.         .spring-date {
  140.             text-align: center;
  141.             font-size: 1.8rem;
  142.             margin: 30px 0;
  143.             color: var(--primary-color);
  144.             font-weight: 600;
  145.         }

  146.         .decorations {
  147.             position: absolute;
  148.             width: 100%;
  149.             height: 100%;
  150.             top: 0;
  151.             left: 0;
  152.             pointer-events: none;
  153.             z-index: 0;
  154.             overflow: hidden;
  155.         }

  156.         /* 福字烟花效果 */
  157.         .fu-firework {
  158.             position: absolute;
  159.             font-size: 2.5rem;
  160.             font-weight: bold;
  161.             color: var(--primary-color);
  162.             z-index: 0;
  163.             opacity: 0;
  164.             pointer-events: none;
  165.             text-shadow: 0 0 10px var(--accent-color);
  166.         }

  167.         .fu-firework-1 {
  168.             bottom: 10%;
  169.             left: 15%;
  170.             animation: fuFirework 3s infinite ease-out;
  171.         }

  172.         .fu-firework-2 {
  173.             bottom: 15%;
  174.             left: 25%;
  175.             animation: fuFirework 4s infinite ease-out;
  176.             animation-delay: 0.5s;
  177.             font-size: 3rem;
  178.             color: var(--secondary-color);
  179.         }

  180.         .fu-firework-3 {
  181.             bottom: 8%;
  182.             left: 40%;
  183.             animation: fuFirework 3.5s infinite ease-out;
  184.             animation-delay: 1s;
  185.             font-size: 2.2rem;
  186.         }

  187.         .fu-firework-4 {
  188.             bottom: 12%;
  189.             left: 60%;
  190.             animation: fuFirework 4.2s infinite ease-out;
  191.             animation-delay: 1.5s;
  192.             color: var(--accent-color);
  193.         }

  194.         .fu-firework-5 {
  195.             bottom: 5%;
  196.             left: 75%;
  197.             animation: fuFirework 3.8s infinite ease-out;
  198.             animation-delay: 2s;
  199.             font-size: 2.8rem;
  200.         }

  201.         .fu-firework-6 {
  202.             bottom: 18%;
  203.             left: 85%;
  204.             animation: fuFirework 4.5s infinite ease-out;
  205.             animation-delay: 2.5s;
  206.             font-size: 2.4rem;
  207.             color: var(--secondary-color);
  208.         }

  209.         /* 更多福字烟花 */
  210.         .fu-firework-7 {
  211.             bottom: 25%;
  212.             left: 10%;
  213.             animation: fuFirework 3.2s infinite ease-out;
  214.             animation-delay: 3s;
  215.             font-size: 2.6rem;
  216.         }

  217.         .fu-firework-8 {
  218.             bottom: 22%;
  219.             left: 30%;
  220.             animation: fuFirework 4s infinite ease-out;
  221.             animation-delay: 3.5s;
  222.             color: var(--accent-color);
  223.         }

  224.         .fu-firework-9 {
  225.             bottom: 30%;
  226.             left: 50%;
  227.             animation: fuFirework 3.7s infinite ease-out;
  228.             animation-delay: 4s;
  229.             font-size: 3.2rem;
  230.         }

  231.         .fu-firework-10 {
  232.             bottom: 28%;
  233.             left: 70%;
  234.             animation: fuFirework 4.3s infinite ease-out;
  235.             animation-delay: 4.5s;
  236.             font-size: 2.3rem;
  237.             color: var(--secondary-color);
  238.         }

  239.         /* 福字烟花动画 */
  240.         @keyframes fuFirework {
  241.             0% {
  242.                 transform: translateY(0) scale(0.5) rotate(0deg);
  243.                 opacity: 0;
  244.             }
  245.             10% {
  246.                 opacity: 1;
  247.             }
  248.             50% {
  249.                 opacity: 0.8;
  250.                 text-shadow: 0 0 20px var(--accent-color), 0 0 30px var(--accent-color);
  251.             }
  252.             100% {
  253.                 transform: translateY(-100vh) scale(1.5) rotate(360deg);
  254.                 opacity: 0;
  255.             }
  256.         }

  257.         .cloud {
  258.             position: absolute;
  259.             background-color: rgba(255, 255, 255, 0.8);
  260.             border-radius: 50%;
  261.             z-index: -1;
  262.         }

  263.         .cloud-1 {
  264.             width: 120px;
  265.             height: 60px;
  266.             top: 5%;
  267.             left: 20%;
  268.             opacity: 0.7;
  269.         }

  270.         .cloud-2 {
  271.             width: 150px;
  272.             height: 70px;
  273.             top: 10%;
  274.             right: 15%;
  275.             opacity: 0.6;
  276.         }

  277.         .cloud-3 {
  278.             width: 100px;
  279.             height: 50px;
  280.             bottom: 10%;
  281.             left: 15%;
  282.             opacity: 0.5;
  283.         }

  284.         /* 静态福字装饰 */
  285.         .fu-character {
  286.             position: absolute;
  287.             font-size: 4rem;
  288.             color: var(--primary-color);
  289.             font-weight: bold;
  290.             opacity: 0.15;
  291.             transform: rotate(-15deg);
  292.             z-index: 0;
  293.         }

  294.         .fu-1 {
  295.             top: 15%;
  296.             left: 8%;
  297.         }

  298.         .fu-2 {
  299.             top: 10%;
  300.             right: 10%;
  301.             transform: rotate(15deg);
  302.         }

  303.         .fu-3 {
  304.             bottom: 15%;
  305.             left: 12%;
  306.             transform: rotate(10deg);
  307.         }

  308.         .fu-4 {
  309.             bottom: 10%;
  310.             right: 8%;
  311.             transform: rotate(-20deg);
  312.         }

  313.         /* 春联装饰 */
  314.         .chunlian {
  315.             position: absolute;
  316.             width: 30px;
  317.             height: 120px;
  318.             background-color: var(--primary-color);
  319.             border-radius: 5px;
  320.             z-index: 0;
  321.         }

  322.         /* .chunlian-left {
  323.             left: 5%;
  324.             top: 25%;
  325.         }

  326.         .chunlian-right {
  327.             right: 5%;
  328.             top: 25%;
  329.         } */

  330.         footer {
  331.             text-align: center;
  332.             padding: 30px 0;
  333.             color: var(--text-color);
  334.             font-size: 1rem;
  335.             opacity: 0.8;
  336.             margin-top: 30px;
  337.         }

  338.         .highlight {
  339.             color: var(--primary-color);
  340.             font-weight: 600;
  341.         }

  342.         /* 响应式设计 */
  343.         @media (max-width: 768px) {
  344.             h1 {
  345.                 font-size: 2.5rem;
  346.             }

  347.             .countdown {
  348.                 gap: 15px;
  349.             }

  350.             .countdown-item {
  351.                 min-width: 120px;
  352.                 padding: 20px 15px;
  353.             }

  354.             .countdown-value {
  355.                 font-size: 3.5rem;
  356.             }

  357.             .countdown-label {
  358.                 font-size: 1.1rem;
  359.             }

  360.             .theme-selector {
  361.                 gap: 10px;
  362.             }

  363.             .theme-btn {
  364.                 padding: 8px 15px;
  365.                 font-size: 0.9rem;
  366.             }

  367.             /* 在小屏幕上减少福字烟花数量 */
  368.             .fu-firework-5,
  369.             .fu-firework-6,
  370.             .fu-firework-7,
  371.             .fu-firework-8,
  372.             .fu-firework-9,
  373.             .fu-firework-10 {
  374.                 display: none;
  375.             }

  376.             .fu-character, .chunlian {
  377.                 display: none;
  378.             }
  379.         }

  380.         @media (max-width: 576px) {
  381.             .countdown-item {
  382.                 min-width: 80px;
  383.                 padding: 15px 10px;
  384.             }

  385.             .countdown-value {
  386.                 font-size: 2.5rem;
  387.             }

  388.             .countdown-label {
  389.                 font-size: 0.9rem;
  390.             }

  391.             h1 {
  392.                 font-size: 2rem;
  393.             }

  394.             .countdown-title {
  395.                 font-size: 1.7rem;
  396.             }

  397.             .spring-date {
  398.                 font-size: 1.3rem;
  399.             }

  400.             /* 在更小的屏幕上进一步减少福字烟花 */
  401.             .fu-firework-3,
  402.             .fu-firework-4 {
  403.                 display: none;
  404.             }

  405.             .fu-firework {
  406.                 font-size: 1.8rem;
  407.             }
  408.         }

  409.         /* 主题样式 */
  410.         /* 传统红色主题 - 默认 */
  411.         .theme-traditional {
  412.             --primary-color: #d32f2f;
  413.             --secondary-color: #ff9800;
  414.             --background-color: #fef5f5;
  415.             --text-color: #333;
  416.             --accent-color: #ffeb3b;
  417.             --panel-color: #fff;
  418.             --shadow-color: rgba(0, 0, 0, 0.1);
  419.         }

  420.         /* 现代金色主题 */
  421.         .theme-modern {
  422.             --primary-color: #d4af37;
  423.             --secondary-color: #c19a6b;
  424.             --background-color: #1a1a1a;
  425.             --text-color: #f5f5f5;
  426.             --accent-color: #ffd700;
  427.             --panel-color: #2a2a2a;
  428.             --shadow-color: rgba(0, 0, 0, 0.3);
  429.         }

  430.         /* 水墨风格主题 */
  431.         .theme-ink {
  432.             --primary-color: #000000;
  433.             --secondary-color: #666666;
  434.             --background-color: #f0f0f0;
  435.             --text-color: #333;
  436.             --accent-color: #8b4513;
  437.             --panel-color: #fff;
  438.             --shadow-color: rgba(0, 0, 0, 0.15);
  439.         }

  440.         /* 蓝调主题 */
  441.         .theme-blue {
  442.             --primary-color: #1e88e5;
  443.             --secondary-color: #42a5f5;
  444.             --background-color: #e3f2fd;
  445.             --text-color: #0d47a1;
  446.             --accent-color: #ffd54f;
  447.             --panel-color: #fff;
  448.             --shadow-color: rgba(30, 136, 229, 0.2);
  449.         }

  450.         /* 新春绿意主题 */
  451.         .theme-green {
  452.             --primary-color: #2e7d32;
  453.             --secondary-color: #4caf50;
  454.             --background-color: #f1f8e9;
  455.             --text-color: #1b5e20;
  456.             --accent-color: #ffb300;
  457.             --panel-color: #fff;
  458.             --shadow-color: rgba(46, 125, 50, 0.2);
  459.         }
  460.     </style>
  461. </head>
  462. <body class="theme-traditional">
  463.     <!-- 装饰元素 -->
  464.     <div class="decorations">
  465.         <!-- 福字烟花效果 -->
  466.         <div class="fu-firework fu-firework-1">福</div>
  467.         <div class="fu-firework fu-firework-2">福</div>
  468.         <div class="fu-firework fu-firework-3">福</div>
  469.         <div class="fu-firework fu-firework-4">福</div>
  470.         <div class="fu-firework fu-firework-5">福</div>
  471.         <div class="fu-firework fu-firework-6">福</div>
  472.         <div class="fu-firework fu-firework-7">福</div>
  473.         <div class="fu-firework fu-firework-8">福</div>
  474.         <div class="fu-firework fu-firework-9">福</div>
  475.         <div class="fu-firework fu-firework-10">福</div>

  476.         <!-- 其他装饰元素 -->
  477.         <div class="cloud cloud-1"></div>
  478.         <div class="cloud cloud-2"></div>
  479.         <div class="cloud cloud-3"></div>

  480.         <!-- 静态福字装饰 -->
  481.         <div class="fu-character fu-1">福</div>
  482.         <div class="fu-character fu-2">福</div>
  483.         <div class="fu-character fu-3">春</div>
  484.         <div class="fu-character fu-4">春</div>

  485.         <!-- 春联装饰 -->
  486.         <!-- <div class="chunlian chunlian-left"></div>
  487.         <div class="chunlian chunlian-right"></div> -->
  488.     </div>

  489.     <div class="container">
  490.         <header>
  491.             <h1>2026年春节倒计时</h1>
  492.             <div class="subtitle">农历丙午年 · 金马迎春 · 阖家欢乐</div>

  493.             <!-- 主题选择器 -->
  494.             <div class="theme-selector">
  495.                 <button class="theme-btn active" data-theme="traditional">
  496.                     <i class="fas fa-fire"></i> 传统红火
  497.                 </button>
  498.                 <button class="theme-btn" data-theme="modern">
  499.                     <i class="fas fa-gem"></i> 现代金耀
  500.                 </button>
  501.                 <button class="theme-btn" data-theme="ink">
  502.                     <i class="fas fa-paint-brush"></i> 水墨丹青
  503.                 </button>
  504.                 <button class="theme-btn" data-theme="blue">
  505.                     <i class="fas fa-snowflake"></i> 冰雪蓝调
  506.                 </button>
  507.                 <button class="theme-btn" data-theme="green">
  508.                     <i class="fas fa-leaf"></i> 新春绿意
  509.                 </button>
  510.             </div>
  511.         </header>

  512.         <main>
  513.             <div class="countdown-container">
  514.                 <div class="countdown-title">
  515.                     <i class="fas fa-hourglass-half"></i>
  516.                     距离2026年春节还有
  517.                 </div>

  518.                 <div class="spring-date">
  519.                     2026年春节:2026年2月17日(星期二)· 农历正月初一
  520.                 </div>

  521.                 <div class="countdown">
  522.                     <div class="countdown-item">
  523.                         <div class="countdown-value" id="days">00</div>
  524.                         <div class="countdown-label">天</div>
  525.                     </div>
  526.                     <div class="countdown-item">
  527.                         <div class="countdown-value" id="hours">00</div>
  528.                         <div class="countdown-label">小时</div>
  529.                     </div>
  530.                     <div class="countdown-item">
  531.                         <div class="countdown-value" id="minutes">00</div>
  532.                         <div class="countdown-label">分钟</div>
  533.                     </div>
  534.                     <div class="countdown-item">
  535.                         <div class="countdown-value" id="seconds">00</div>
  536.                         <div class="countdown-label">秒</div>
  537.                     </div>
  538.                 </div>

  539.                 <div class="spring-date" style="font-size: 1.4rem; margin-top: 20px;">
  540.                     <i class="fas fa-horse"></i> 2026年是农历丙午年(马年)
  541.                 </div>
  542.             </div>
  543.         </main>

  544.         <footer>
  545.             <p>© 2026春节倒计时 | 作者:<span class="highlight">牛马论坛</span></p>
  546.             <p>祝福您和您的家人:<span class="highlight">马到成功 · 万事如意 · 阖家幸福 · 新春大吉</span></p>
  547.         </footer>
  548.     </div>

  549.     <script>
  550.         // 设置2026年春节日期:2026年2月17日(星期二)
  551.         const springFestivalDate = new Date('2026-02-17T00:00:00');

  552.         // 更新倒计时
  553.         function updateCountdown() {
  554.             const now = new Date();
  555.             const timeDifference = springFestivalDate - now;

  556.             // 如果春节已经过了
  557.             if (timeDifference < 0) {
  558.                 document.getElementById('days').textContent = '00';
  559.                 document.getElementById('hours').textContent = '00';
  560.                 document.getElementById('minutes').textContent = '00';
  561.                 document.getElementById('seconds').textContent = '00';
  562.                 return;
  563.             }

  564.             // 计算剩余的天、小时、分钟和秒
  565.             const days = Math.floor(timeDifference / (1000 * 60 * 60 * 24));
  566.             const hours = Math.floor((timeDifference % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
  567.             const minutes = Math.floor((timeDifference % (1000 * 60 * 60)) / (1000 * 60));
  568.             const seconds = Math.floor((timeDifference % (1000 * 60)) / 1000);

  569.             // 更新显示
  570.             document.getElementById('days').textContent = days.toString().padStart(2, '0');
  571.             document.getElementById('hours').textContent = hours.toString().padStart(2, '0');
  572.             document.getElementById('minutes').textContent = minutes.toString().padStart(2, '0');
  573.             document.getElementById('seconds').textContent = seconds.toString().padStart(2, '0');
  574.         }

  575.         // 初始化倒计时
  576.         updateCountdown();
  577.         setInterval(updateCountdown, 1000);

  578.         // 主题切换功能
  579.         document.querySelectorAll('.theme-btn').forEach(button => {
  580.             button.addEventListener('click', function() {
  581.                 // 移除所有按钮的active类
  582.                 document.querySelectorAll('.theme-btn').forEach(btn => {
  583.                     btn.classList.remove('active');
  584.                 });

  585.                 // 给当前点击的按钮添加active类
  586.                 this.classList.add('active');

  587.                 // 获取主题名称
  588.                 const theme = this.getAttribute('data-theme');

  589.                 // 移除现有主题类并添加新主题类
  590.                 document.body.className = '';
  591.                 document.body.classList.add(`theme-${theme}`);

  592.                 // 保存主题到本地存储
  593.                 localStorage.setItem('2026-countdown-theme', theme);
  594.             });
  595.         });

  596.         // 页面加载时恢复保存的主题
  597.         window.addEventListener('load', function() {
  598.             const savedTheme = localStorage.getItem('2026-countdown-theme');
  599.             if (savedTheme) {
  600.                 // 移除所有按钮的active类
  601.                 document.querySelectorAll('.theme-btn').forEach(btn => {
  602.                     btn.classList.remove('active');
  603.                 });

  604.                 // 激活保存的主题按钮
  605.                 const activeButton = document.querySelector(`[data-theme="${savedTheme}"]`);
  606.                 if (activeButton) {
  607.                     activeButton.classList.add('active');
  608.                 }

  609.                 // 应用保存的主题
  610.                 document.body.className = '';
  611.                 document.body.classList.add(`theme-${savedTheme}`);
  612.             }
  613.         });

  614.         // 添加一些春节祝福语
  615.         const blessings = [
  616.             "金马迎春,万象更新",
  617.             "马到成功,前程似锦",
  618.             "年年有余,岁岁平安",
  619.             "福星高照,万事如意",
  620.             "新春快乐,阖家幸福"
  621.         ];

  622.         // 随机显示祝福语
  623.         function showRandomBlessing() {
  624.             const blessingElement = document.querySelector('.subtitle');
  625.             if (blessingElement) {
  626.                 const randomIndex = Math.floor(Math.random() * blessings.length);
  627.                 blessingElement.textContent = blessings[randomIndex];

  628.                 // 每隔10秒更换一次祝福语
  629.                 setInterval(() => {
  630.                     const newIndex = Math.floor(Math.random() * blessings.length);
  631.                     blessingElement.textContent = blessings[newIndex];
  632.                 }, 10000);
  633.             }
  634.         }

  635.         // 页面加载完成后显示随机祝福语
  636.         window.addEventListener('load', showRandomBlessing);

  637.         // 添加一些交互效果
  638.         document.querySelectorAll('.countdown-item').forEach(item => {
  639.             item.addEventListener('mouseenter', function() {
  640.                 this.style.transform = 'scale(1.05)';
  641.                 this.style.transition = 'transform 0.3s ease';
  642.             });

  643.             item.addEventListener('mouseleave', function() {
  644.                 this.style.transform = 'scale(1)';
  645.             });
  646.         });

  647.         // 动态生成更多福字烟花
  648.         function createFuFireworks() {
  649.             const decorations = document.querySelector('.decorations');

  650.             // 如果已经有足够的福字烟花,就不再创建
  651.             if (document.querySelectorAll('.fu-firework').length >= 10) return;

  652.             // 创建额外的福字烟花
  653.             for (let i = 11; i <= 16; i++) {
  654.                 const fu = document.createElement('div');
  655.                 fu.className = `fu-firework fu-firework-${i}`;
  656.                 fu.textContent = '福';

  657.                 // 随机位置
  658.                 const left = Math.random() * 90 + 5; // 5% 到 95%
  659.                 const bottom = Math.random() * 20 + 5; // 5% 到 25%

  660.                 // 随机动画参数
  661.                 const duration = Math.random() * 2 + 3; // 3到5秒
  662.                 const delay = Math.random() * 5; // 0到5秒延迟
  663.                 const fontSize = Math.random() * 1 + 2; // 2到3rem
  664.                 const colorIndex = Math.floor(Math.random() * 3);
  665.                 const colors = ['var(--primary-color)', 'var(--secondary-color)', 'var(--accent-color)'];

  666.                 // 应用样式
  667.                 fu.style.left = `${left}%`;
  668.                 fu.style.bottom = `${bottom}%`;
  669.                 fu.style.fontSize = `${fontSize}rem`;
  670.                 fu.style.color = colors[colorIndex];
  671.                 fu.style.animation = `fuFirework ${duration}s infinite ease-out`;
  672.                 fu.style.animationDelay = `${delay}s`;

  673.                 decorations.appendChild(fu);
  674.             }
  675.         }

  676.         // 页面加载后创建动态福字烟花
  677.         window.addEventListener('load', () => {
  678.             // 等一会儿再创建额外的福字烟花
  679.             setTimeout(createFuFireworks, 2000);

  680.             // 每隔一段时间重新创建一些福字烟花
  681.             setInterval(() => {
  682.                 // 随机移除一些福字烟花
  683.                 const fuFireworks = document.querySelectorAll('.fu-firework');
  684.                 if (fuFireworks.length > 15) {
  685.                     const removeCount = Math.floor(Math.random() * 3) + 1;
  686.                     for (let i = 0; i < removeCount && i < fuFireworks.length; i++) {
  687.                         if (fuFireworks[i].className.includes('fu-firework-1') ||
  688.                             fuFireworks[i].className.includes('fu-firework-2') ||
  689.                             fuFireworks[i].className.includes('fu-firework-3') ||
  690.                             fuFireworks[i].className.includes('fu-firework-4') ||
  691.                             fuFireworks[i].className.includes('fu-firework-5') ||
  692.                             fuFireworks[i].className.includes('fu-firework-6') ||
  693.                             fuFireworks[i].className.includes('fu-firework-7') ||
  694.                             fuFireworks[i].className.includes('fu-firework-8') ||
  695.                             fuFireworks[i].className.includes('fu-firework-9') ||
  696.                             fuFireworks[i].className.includes('fu-firework-10')) {
  697.                             // 保留前10个固定的福字烟花
  698.                             continue;
  699.                         }
  700.                         fuFireworks[i].remove();
  701.                     }
  702.                 }

  703.                 // 创建新的福字烟花
  704.                 createFuFireworks();
  705.             }, 8000);
  706.         });
  707.     </script>
  708. </body>
  709. </html>
复制代码


生命在于折腾,牛马点缀生活。

回复

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

hot.热文换一批
最新热评 加载中...
牛马论坛(niumabbs.com),一个专注于分享日常新鲜事、职场工作点滴、摸鱼乐趣与各类生活感悟的交流平台。

    关注我们

  • 加入Q群
  • 微信客服
  • QQ客服
Copyright © 2026 NIUMABBS 版权所有 All Rights Reserved. 劰载中...
关灯 在本版发帖
扫一扫添加微信客服
QQ客服返回顶部
快速回复 返回顶部 返回列表