AI写的弹窗公告代码

以下是这份公告弹窗代码的完整功能介绍,涵盖设计特点、核心功能和交互逻辑:### **一、视觉设计与动画效果**1. **现代玻璃态UI**     – 采用半透明背景(`rgba(255, 255, 255, 0.9)`)搭配毛玻璃效果(`backdrop-filter: blur(12px)`),与页面背景自然融合     – 圆角设计(24px)+ 柔和阴影(`0 20px 50px rgba(0, 0, 0, 0.12)`),增强立体感     – 顶部渐变装饰条(`#4361ee` 到 `#3a0ca3`),提升视觉焦点2. **分层入场动画**     – 弹窗内元素按顺序依次出现(图标→标题→内容→倒计时→按钮→底部信息),每个元素延迟不同时间,形成流畅的层次感     – 动画类型包括:缩放弹出(`popIn`)、淡入上移(`fadeInUp`)、简单淡入(`fadeIn`),增强页面活力3. **微交互效果**     – 倒计时数字变化时触发脉冲动画(轻微放大后恢复),直观提示时间流逝     – 按钮悬停时显示流光效果(透明光带从左到右滑动),提升交互反馈     – 关闭按钮悬停时旋转+缩放,增强操作感知### **二、核心功能与逻辑**1. **智能倒计时系统**     – **双阶段倒计时**:活动开始前显示“距离开始时间”,开始后自动切换为“距离结束时间”(活动时间固定为10月16日-10月26日)     – **动态更新**:每秒刷新倒计时数字(天/时/分/秒),并自动补零保持格式统一(如“03天”而非“3天”)     – **结束处理**:活动结束后自动显示“活动已结束”提示,并禁用“参加活动”按钮2. **显示频率控制**     – 关闭弹窗后,通过`localStorage`记录关闭时间,**3小时内不再重复显示**,平衡曝光率与用户体验     – 3小时后自动失效,重新打开页面会再次显示,确保用户不会错过活动关键信息3. **多场景适配**     – **响应式设计**:在手机、平板、电脑上自动调整布局(如移动端按钮纵向排列)     – **内容自适应**:根据活动阶段(未开始/进行中/已结束)自动切换公告文案,保持信息准确性### **三、交互与操作设计**1. **多种关闭方式**     – 点击右上角关闭按钮(×)     – 点击“我知道了”按钮     – 点击弹窗外部背景区域     – 按下键盘ESC键     所有关闭方式均会触发淡出动画,提升操作流畅度2. **活动跳转功能**     – “参加活动”按钮默认链接到指定地址(`https://www.fwq123.com.com`),点击后在新窗口打开     – 活动未开始时按钮置灰不可点击,开始后自动激活,引导用户参与### **四、技术特点**1. **纯前端实现**:无需后端支持,通过HTML+CSS+JavaScript完成所有功能,可直接嵌入任何网站  2. **无依赖**:不依赖jQuery等框架,代码轻量且独立,避免与现有网站代码冲突  3. **性能优化**:     – 关闭弹窗时自动清除倒计时定时器,避免内存泄漏     – 动画仅在必要时触发(如数字变化时才显示脉冲效果)     – 通过`localStorage`实现状态记录,无需频繁操作DOM### **总结**这份代码是一个功能完整、体验优良的活动公告弹窗,既具备视觉吸引力(玻璃态设计+流畅动画),又通过智能倒计时和频率控制实现了高效的信息传递,同时兼顾了多设备适配和操作便捷性,适合各类网站的活动推广场景。

AI写的弹窗公告代码

  1. <script>
  2. // 动态公告弹窗生成函数
  3. function createAnnouncementPopup() {
  4.     // 检查是否在三小时内已关闭过弹窗
  5.     const lastClosedTime = localStorage.getItem(‘popupLastClosed’);
  6.     const now = new Date().getTime();
  7.     const threeHours = 3 * 60 * 60 * 1000; // 三小时的毫秒数
  8.     // 如果三小时内关闭过,则不显示
  9.     if (lastClosedTime && (now – parseInt(lastClosedTime) < threeHours)) {
  10.         return;
  11.     }
  12.     // 创建样式
  13.     const style = document.createElement(‘style’);
  14.     style.textContent = `
  15.         .announcement-popup {
  16.             position: fixed;
  17.             top: 0;
  18.             left: 0;
  19.             width: 100%;
  20.             height: 100%;
  21.             background: rgba(0, 0, 0, 0.25);
  22.             backdrop-filter: blur(8px);
  23.             display: flex;
  24.             align-items: center;
  25.             justify-content: center;
  26.             z-index: 9999;
  27.             opacity: 0;
  28.             visibility: hidden;
  29.             transition: opacity 0.6s cubic-bezier(0.34, 1.56, 0.64, 1), visibility 0.6s cubic-bezier(0.34, 1.56, 0.64, 1);
  30.             padding: 1rem;
  31.         }
  32.         .announcement-popup.active {
  33.             opacity: 1;
  34.             visibility: visible;
  35.         }
  36.         .popup-content {
  37.             background: rgba(255, 255, 255, 0.9);
  38.             border-radius: 24px;
  39.             width: 100%;
  40.             max-width: 550px;
  41.             padding: 2.5rem 2rem;
  42.             position: relative;
  43.             transform: translateY(40px) scale(0.95);
  44.             opacity: 0;
  45.             transition: transform 0.6s cubic-bezier(0.34, 1.56, 0.64, 1), opacity 0.6s cubic-bezier(0.34, 1.56, 0.64, 1);
  46.             box-shadow: 0 20px 50px rgba(0, 0, 0, 0.12);
  47.             backdrop-filter: blur(12px);
  48.             border: 1px solid rgba(255, 255, 255, 0.7);
  49.             overflow: hidden;
  50.         }
  51.         .announcement-popup.active .popup-content {
  52.             transform: translateY(0) scale(1);
  53.             opacity: 1;
  54.         }
  55.         .popup-content::before {
  56.             content: ”;
  57.             position: absolute;
  58.             top: 0;
  59.             left: 0;
  60.             width: 100%;
  61.             height: 8px;
  62.             background: linear-gradient(90deg, #4361ee, #3a0ca3);
  63.         }
  64.         .popup-close {
  65.             position: absolute;
  66.             top: 1.5rem;
  67.             right: 1.5rem;
  68.             background: rgba(255, 255, 255, 0.7);
  69.             border: none;
  70.             font-size: 1.2rem;
  71.             cursor: pointer;
  72.             color: #4a4a4a;
  73.             transition: all 0.3s ease;
  74.             width: 38px;
  75.             height: 38px;
  76.             border-radius: 50%;
  77.             display: flex;
  78.             align-items: center;
  79.             justify-content: center;
  80.             box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
  81.             z-index: 10;
  82.             transform: translate(10px, -10px) scale(0);
  83.             animation: popIn 0.5s cubic-bezier(0.34, 1.56, 0.64, 1) 0.5s forwards;
  84.         }
  85.         .popup-close:hover {
  86.             color: #2d2d2d;
  87.             background: white;
  88.             transform: rotate(90deg) scale(1.1);
  89.             box-shadow: 0 4px 12px rgba(0, 0, 0, 0.12);
  90.         }
  91.         .popup-icon {
  92.             width: 80px;
  93.             height: 80px;
  94.             background: linear-gradient(135deg, #e0e7ff, #c7d2fe);
  95.             border-radius: 50%;
  96.             display: flex;
  97.             align-items: center;
  98.             justify-content: center;
  99.             margin: 0 auto 2rem;
  100.             box-shadow: 0 6px 16px rgba(67, 97, 238, 0.15);
  101.             position: relative;
  102.             overflow: hidden;
  103.             transform: scale(0);
  104.             animation: popIn 0.5s cubic-bezier(0.34, 1.56, 0.64, 1) 0.2s forwards;
  105.         }
  106.         .popup-icon::after {
  107.             content: ”;
  108.             position: absolute;
  109.             top: -15px;
  110.             right: -15px;
  111.             width: 40px;
  112.             height: 40px;
  113.             background: rgba(255, 255, 255, 0.3);
  114.             border-radius: 50%;
  115.         }
  116.         .popup-icon svg {
  117.             width: 38px;
  118.             height: 38px;
  119.             color: #4361ee;
  120.             position: relative;
  121.             z-index: 1;
  122.             transform: scale(0.8);
  123.             animation: scaleIn 0.4s ease 0.4s forwards;
  124.         }
  125.         .popup-title {
  126.             font-size: 1.8rem;
  127.             font-weight: 700;
  128.             color: #1e293b;
  129.             text-align: center;
  130.             margin-bottom: 1.5rem;
  131.             line-height: 1.3;
  132.             text-shadow: 0 1px 2px rgba(255, 255, 255, 0.6);
  133.             letter-spacing: -0.02em;
  134.             opacity: 0;
  135.             transform: translateY(20px);
  136.             animation: fadeInUp 0.5s ease 0.6s forwards;
  137.         }
  138.         .popup-message {
  139.             color: #334155;
  140.             text-align: center;
  141.             line-height: 1.8;
  142.             margin-bottom: 1.8rem;
  143.             font-size: 1.1rem;
  144.             padding: 0 1rem;
  145.             text-shadow: 0 1px 1px rgba(255, 255, 255, 0.8);
  146.             opacity: 0;
  147.             transform: translateY(20px);
  148.             animation: fadeInUp 0.5s ease 0.7s forwards;
  149.         }
  150.         /* 倒计时样式 */
  151.         .countdown-container {
  152.             text-align: center;
  153.             margin-bottom: 2.2rem;
  154.             padding: 0 0.5rem;
  155.             opacity: 0;
  156.             animation: fadeIn 0.6s ease 0.8s forwards;
  157.         }
  158.         .countdown-title {
  159.             font-size: 1.05rem;
  160.             color: #d946ef;
  161.             font-weight: 600;
  162.             margin-bottom: 1rem;
  163.             text-shadow: 0 1px 1px rgba(255, 255, 255, 0.6);
  164.             letter-spacing: 0.03em;
  165.         }
  166.         .countdown-timer {
  167.             display: flex;
  168.             justify-content: center;
  169.             gap: 1rem;
  170.         }
  171.         .countdown-item {
  172.             background: rgba(255, 255, 255, 0.9);
  173.             padding: 1rem 0.8rem;
  174.             border-radius: 12px;
  175.             min-width: 68px;
  176.             box-shadow: 0 4px 12px rgba(0, 0, 0, 0.07);
  177.             border: 1px solid rgba(255, 255, 255, 0.8);
  178.             position: relative;
  179.             overflow: hidden;
  180.             transform: scale(0.9);
  181.             opacity: 0;
  182.         }
  183.         .countdown-item:nth-child(1) { animation: popIn 0.4s ease 0.9s forwards; }
  184.         .countdown-item:nth-child(2) { animation: popIn 0.4s ease 1.0s forwards; }
  185.         .countdown-item:nth-child(3) { animation: popIn 0.4s ease 1.1s forwards; }
  186.         .countdown-item:nth-child(4) { animation: popIn 0.4s ease 1.2s forwards; }
  187.         .countdown-item::before {
  188.             content: ”;
  189.             position: absolute;
  190.             top: 0;
  191.             left: 0;
  192.             width: 100%;
  193.             height: 3px;
  194.             background: linear-gradient(90deg, #4361ee, #d946ef);
  195.             opacity: 0;
  196.             transition: opacity 0.3s ease;
  197.         }
  198.         .countdown-item:hover::before {
  199.             opacity: 1;
  200.         }
  201.         .countdown-number {
  202.             font-size: 1.6rem;
  203.             font-weight: 700;
  204.             color: #1e293b;
  205.             line-height: 1;
  206.             text-shadow: 0 1px 2px rgba(255, 255, 255, 0.7);
  207.             font-variant-numeric: tabular-nums;
  208.             transition: transform 0.3s ease;
  209.         }
  210.         .countdown-number.changed {
  211.             animation: pulse 0.3s ease;
  212.         }
  213.         .countdown-label {
  214.             font-size: 0.8rem;
  215.             color: #475569;
  216.             margin-top: 0.5rem;
  217.             text-shadow: 0 1px 1px rgba(255, 255, 255, 0.8);
  218.             text-transform: uppercase;
  219.             letter-spacing: 0.05em;
  220.         }
  221.         .popup-buttons {
  222.             display: flex;
  223.             gap: 1.2rem;
  224.             margin-bottom: 1.2rem;
  225.             padding: 0 0.5rem;
  226.             opacity: 0;
  227.             animation: fadeIn 0.6s ease 1.3s forwards;
  228.         }
  229.         .popup-cta, .popup-action {
  230.             flex: 1;
  231.             border: none;
  232.             padding: 1.1rem 1rem;
  233.             border-radius: 14px;
  234.             font-size: 1.05rem;
  235.             font-weight: 600;
  236.             cursor: pointer;
  237.             transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
  238.             text-align: center;
  239.             white-space: nowrap;
  240.             opacity: 0.95;
  241.             text-shadow: 0 1px 1px rgba(0, 0, 0, 0.1);
  242.             position: relative;
  243.             overflow: hidden;
  244.             transform: translateY(20px);
  245.             opacity: 0;
  246.         }
  247.         .popup-cta {
  248.             background: linear-gradient(135deg, #4361ee, #3a0ca3);
  249.             color: white;
  250.             box-shadow: 0 6px 18px rgba(67, 97, 238, 0.25);
  251.             animation: fadeInUp 0.5s ease 1.4s forwards;
  252.         }
  253.         .popup-action {
  254.             background: linear-gradient(135deg, #f72585, #d946ef);
  255.             color: white;
  256.             box-shadow: 0 6px 18px rgba(217, 70, 239, 0.25);
  257.             text-decoration: none;
  258.             display: flex;
  259.             align-items: center;
  260.             justify-content: center;
  261.             animation: fadeInUp 0.5s ease 1.5s forwards;
  262.         }
  263.         .popup-cta::after, .popup-action::after {
  264.             content: ”;
  265.             position: absolute;
  266.             top: 0;
  267.             left: -100%;
  268.             width: 100%;
  269.             height: 100%;
  270.             background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.2), transparent);
  271.             transition: all 0.6s ease;
  272.         }
  273.         .popup-cta:hover::after, .popup-action:hover::after {
  274.             left: 100%;
  275.         }
  276.         .popup-cta:hover {
  277.             transform: translateY(-4px);
  278.             box-shadow: 0 8px 24px rgba(67, 97, 238, 0.35);
  279.             opacity: 1;
  280.         }
  281.         .popup-action:hover {
  282.             transform: translateY(-4px);
  283.             box-shadow: 0 8px 24px rgba(217, 70, 239, 0.35);
  284.             opacity: 1;
  285.         }
  286.         .popup-cta:active, .popup-action:active {
  287.             transform: translateY(-2px);
  288.         }
  289.         .popup-footer {
  290.             text-align: center;
  291.             margin-top: 1.5rem;
  292.             font-size: 0.9rem;
  293.             color: #58667e;
  294.             line-height: 1.6;
  295.             text-shadow: 0 1px 1px rgba(255, 255, 255, 0.8);
  296.             padding: 0 1rem;
  297.             opacity: 0;
  298.             animation: fadeIn 0.6s ease 1.6s forwards;
  299.         }
  300.         /* 动画关键帧定义 */
  301.         @keyframes fadeIn {
  302.             from { opacity: 0; }
  303.             to { opacity: 1; }
  304.         }
  305.         @keyframes fadeInUp {
  306.             from {
  307.                 opacity: 0;
  308.                 transform: translateY(20px);
  309.             }
  310.             to {
  311.                 opacity: 1;
  312.                 transform: translateY(0);
  313.             }
  314.         }
  315.         @keyframes popIn {
  316.             0% {
  317.                 opacity: 0;
  318.                 transform: scale(0.8);
  319.             }
  320.             70% {
  321.                 transform: scale(1.05);
  322.             }
  323.             100% {
  324.                 opacity: 1;
  325.                 transform: scale(1);
  326.             }
  327.         }
  328.         @keyframes scaleIn {
  329.             from { transform: scale(0.8); }
  330.             to { transform: scale(1); }
  331.         }
  332.         @keyframes pulse {
  333.             0% { transform: scale(1); }
  334.             50% { transform: scale(1.15); }
  335.             100% { transform: scale(1); }
  336.         }
  337.         @media (max-width: 480px) {
  338.             .popup-content {
  339.                 padding: 2rem 1.5rem;
  340.                 border-radius: 20px;
  341.             }
  342.             .popup-buttons {
  343.                 flex-direction: column;
  344.                 gap: 1rem;
  345.             }
  346.             .popup-title {
  347.                 font-size: 1.6rem;
  348.                 margin-bottom: 1.2rem;
  349.             }
  350.             .popup-message {
  351.                 font-size: 1rem;
  352.                 margin-bottom: 1.5rem;
  353.             }
  354.             .countdown-container {
  355.                 margin-bottom: 1.8rem;
  356.             }
  357.             .countdown-item {
  358.                 min-width: 60px;
  359.                 padding: 0.8rem 0.6rem;
  360.             }
  361.             .countdown-number {
  362.                 font-size: 1.4rem;
  363.             }
  364.             .popup-cta, .popup-action {
  365.                 padding: 1.05rem;
  366.                 font-size: 1rem;
  367.             }
  368.             .popup-icon {
  369.                 width: 70px;
  370.                 height: 70px;
  371.                 margin-bottom: 1.8rem;
  372.             }
  373.         }
  374.     `;
  375.     document.head.appendChild(style);
  376.     // 创建弹窗HTML
  377.     const popup = document.createElement(‘div’);
  378.     popup.className = ‘announcement-popup’;
  379.     popup.innerHTML = `
  380.         <div class=”popup-content”>
  381.             <button class=”popup-close”>&times;</button>
  382.             <div class=”popup-icon”>
  383.                 <svg xmlns=”http://www.w3.org/2000/svg” fill=”none” viewBox=”0 0 24 24″ stroke=”currentColor”>
  384.                     <path stroke-linecap=”round” stroke-linejoin=”round” stroke-width=”2″ d=”M12 8v4l3 3m6-3a9 9 0 11-18 0 9 9 0 0118 0z” />
  385.                 </svg>
  386.             </div>
  387.             <h3 class=”popup-title”>限时活动公告</h3>
  388.             <p class=”popup-message” id=”popupMessage”>
  389.                 年度回馈活动即将开始!设置提醒,第一时间参与活动,抢占丰厚奖励!
  390.             </p>
  391.             <!– 倒计时区域 –>
  392.             <div class=”countdown-container”>
  393.                 <div class=”countdown-title” id=”countdownTitle”>活动开始倒计时</div>
  394.                 <div class=”countdown-timer”>
  395.                     <div class=”countdown-item”>
  396.                         <div class=”countdown-number” id=”days”>00</div>
  397.                         <div class=”countdown-label”>天</div>
  398.                     </div>
  399.                     <div class=”countdown-item”>
  400.                         <div class=”countdown-number” id=”hours”>00</div>
  401.                         <div class=”countdown-label”>时</div>
  402.                     </div>
  403.                     <div class=”countdown-item”>
  404.                         <div class=”countdown-number” id=”minutes”>00</div>
  405.                         <div class=”countdown-label”>分</div>
  406.                     </div>
  407.                     <div class=”countdown-item”>
  408.                         <div class=”countdown-number” id=”seconds”>00</div>
  409.                         <div class=”countdown-label”>秒</div>
  410.                     </div>
  411.                 </div>
  412.             </div>
  413.             <div class=”popup-buttons”>
  414.                 <button class=”popup-cta”>我知道了</button>
  415.                 <a href=”https://www.xkwo.com/” target=”_blank” class=”popup-action” id=”actionButton” style=”opacity:0.7;pointer-events:none;”>
  416.                     活动未开始
  417.                 </a>
  418.             </div>
  419.             <div class=”popup-footer”>活动时间:10月16日-10月26日 | 如有疑问,请联系在线客服</div>
  420.         </div>
  421.     `;
  422.     document.body.appendChild(popup);
  423.     // 显示弹窗(延迟1秒,让页面加载完成)
  424.     setTimeout(() => {
  425.         popup.classList.add(‘active’);
  426.     }, 1000);
  427.     // 关闭弹窗的核心函数 – 记录关闭时间
  428.     function closePopup() {
  429.         // 记录当前关闭时间到localStorage
  430.         localStorage.setItem(‘popupLastClosed’, now.toString());
  431.         popup.classList.remove(‘active’);
  432.         // 清除倒计时定时器
  433.         if (window.countdownTimer) {
  434.             clearInterval(window.countdownTimer);
  435.             window.countdownTimer = null;
  436.         }
  437.         // 动画结束后移除弹窗
  438.         setTimeout(() => {
  439.             if (popup.parentNode) {
  440.                 popup.remove();
  441.             }
  442.         }, 600);
  443.     }
  444.     // 倒计时功能实现 – 带数字变化动画
  445.     function startSmartCountdown() {
  446.         // 保存上次倒计时数值,用于检测变化
  447.         let lastValues = { days: ’00’, hours: ’00’, minutes: ’00’, seconds: ’00’ };
  448.         // 设置活动时间
  449.         const startTime = new Date();
  450.         startTime.setMonth(9);
  451.         startTime.setDate(16);
  452.         startTime.setHours(0, 0, 0, 0);
  453.         const endTime = new Date();
  454.         endTime.setMonth(9);
  455.         endTime.setDate(26);
  456.         endTime.setHours(23, 59, 59, 0);
  457.         const now = new Date();
  458.         let targetTime, isBeforeStart;
  459.         if (now < startTime) {
  460.             targetTime = startTime;
  461.             isBeforeStart = true;
  462.         } else if (now <= endTime) {
  463.             targetTime = endTime;
  464.             isBeforeStart = false;
  465.             updateForActiveEvent();
  466.         } else {
  467.             document.getElementById(‘countdownTitle’).innerText = ‘活动已结束’;
  468.             document.getElementById(‘countdown-timer’).innerHTML = ‘<div style=”color:#58667e;padding:1rem 0;”>敬请期待下次活动</div>’;
  469.             document.getElementById(‘popupMessage’).textContent = ‘本次年度回馈活动已圆满结束,感谢您的参与!更多精彩活动敬请关注。’;
  470.             document.getElementById(‘actionButton’).textContent = ‘活动已结束’;
  471.             return;
  472.         }
  473.         function updateForActiveEvent() {
  474.             document.getElementById(‘countdownTitle’).innerText = ‘活动剩余时间’;
  475.             document.getElementById(‘popupMessage’).textContent = ‘年度回馈活动火热进行中!参与活动即可获得丰厚奖励,抓紧时间点击参与,错过再等一年!’;
  476.             document.getElementById(‘actionButton’).textContent = ‘参加活动’;
  477.             document.getElementById(‘actionButton’).style.opacity = ‘0.95’;
  478.             document.getElementById(‘actionButton’).style.pointerEvents = ‘auto’;
  479.         }
  480.         function updateCountdown() {
  481.             const now = new Date().getTime();
  482.             const distance = targetTime – now;
  483.             if (isBeforeStart && now >= startTime) {
  484.                 targetTime = endTime;
  485.                 isBeforeStart = false;
  486.                 updateForActiveEvent();
  487.             }
  488.             // 计算时间差
  489.             const days = Math.floor(distance / (1000 * 60 * 60 * 24)).toString().padStart(2, ‘0’);
  490.             const hours = Math.floor((distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60)).toString().padStart(2, ‘0’);
  491.             const minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60)).toString().padStart(2, ‘0’);
  492.             const seconds = Math.floor((distance % (1000 * 60)) / 1000).toString().padStart(2, ‘0’);
  493.             // 更新DOM并添加变化动画
  494.             const elements = {
  495.                 days: document.getElementById(‘days’),
  496.                 hours: document.getElementById(‘hours’),
  497.                 minutes: document.getElementById(‘minutes’),
  498.                 seconds: document.getElementById(‘seconds’)
  499.             };
  500.             // 检查每个数值是否变化,变化则添加动画
  501.             if (days !== lastValues.days) {
  502.                 elements.days.innerText = days;
  503.                 elements.days.classList.add(‘changed’);
  504.                 setTimeout(() => elements.days.classList.remove(‘changed’), 300);
  505.                 lastValues.days = days;
  506.             }
  507.             if (hours !== lastValues.hours) {
  508.                 elements.hours.innerText = hours;
  509.                 elements.hours.classList.add(‘changed’);
  510.                 setTimeout(() => elements.hours.classList.remove(‘changed’), 300);
  511.                 lastValues.hours = hours;
  512.             }
  513.             if (minutes !== lastValues.minutes) {
  514.                 elements.minutes.innerText = minutes;
  515.                 elements.minutes.classList.add(‘changed’);
  516.                 setTimeout(() => elements.minutes.classList.remove(‘changed’), 300);
  517.                 lastValues.minutes = minutes;
  518.             }
  519.             if (seconds !== lastValues.seconds) {
  520.                 elements.seconds.innerText = seconds;
  521.                 elements.seconds.classList.add(‘changed’);
  522.                 setTimeout(() => elements.seconds.classList.remove(‘changed’), 300);
  523.                 lastValues.seconds = seconds;
  524.             }
  525.             // 活动结束处理
  526.             if (distance < 0 && !isBeforeStart) {
  527.                 clearInterval(window.countdownTimer);
  528.                 window.countdownTimer = null;
  529.                 document.getElementById(‘countdownTitle’).innerText = ‘活动已结束’;
  530.                 document.getElementById(‘countdown-timer’).innerHTML = ‘<div style=”color:#58667e;padding:1rem 0;”>敬请期待下次活动</div>’;
  531.                 document.getElementById(‘popupMessage’).textContent = ‘本次年度回馈活动已圆满结束,感谢您的参与!更多精彩活动敬请关注。’;
  532.                 document.getElementById(‘actionButton’).textContent = ‘活动已结束’;
  533.                 document.getElementById(‘actionButton’).style.opacity = ‘0.7’;
  534.                 document.getElementById(‘actionButton’).style.pointerEvents = ‘none’;
  535.             }
  536.         }
  537.         updateCountdown();
  538.         window.countdownTimer = setInterval(updateCountdown, 1000);
  539.     }
  540.     // 启动倒计时
  541.     startSmartCountdown();
  542.     // 绑定关闭事件
  543.     const closeBtn = popup.querySelector(‘.popup-close’);
  544.     const ctaBtn = popup.querySelector(‘.popup-cta’);
  545.     closeBtn.addEventListener(‘click’, () => closePopup());
  546.     ctaBtn.addEventListener(‘click’, () => closePopup());
  547.     popup.addEventListener(‘click’, (e) => {
  548.         if (e.target === popup) closePopup();
  549.     });
  550.     const handleEscKey = (e) => {
  551.         if (e.key === ‘Escape’ && popup.classList.contains(‘active’)) {
  552.             closePopup();
  553.             document.removeEventListener(‘keydown’, handleEscKey);
  554.         }
  555.     };
  556.     document.addEventListener(‘keydown’, handleEscKey);
  557. }
  558. // 页面加载完成后执行
  559. if (document.readyState === ‘loading’) {
  560.     document.addEventListener(‘DOMContentLoaded’, () => {
  561.         setTimeout(createAnnouncementPopup, 500);
  562.     });
  563. } else {
  564.     setTimeout(createAnnouncementPopup, 500);
  565. }
  566. </script>

复制代码

【版权声明】:服务器导航网所有内容均来自网络和部分原创,若无意侵犯到您的权利,请及时与联系 QQ 2232175042,将在48小时内删除相关内容!!

给TA服务器
共{{data.count}}人
人已服务器
其它源码

最新社区源码,对接迅睿cms

2025-10-19 13:41:44

其它源码

彩虹云商城花粥沉梦云商城用户后台美化版

2025-10-19 13:56:50

0 条回复 A文章作者 M管理员
    暂无讨论,说说你的看法吧
个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
搜索