微件:倒计时/js:修订间差异

来自黑神话百科
跳转到导航 跳转到搜索
(显示秒数)
无编辑摘要
 
(未显示2个用户的6个中间版本)
第1行: 第1行:
<includeonly><script>
<includeonly><script type="text/javascript">
document.addEventListener("DOMContentLoaded", function () {
    if(document.readyState == 'interactive' || document.readyState == 'complete') {
  CountDownShort();
        // 页面已加载完成
  var i = window.setInterval(function () {
        window.setInterval(CountDownShort, 1000);
     if (new Date().getSeconds() == 0) {
     } else {
      window.clearInterval(i);
        // 没加载完,监听加载完成事件
      CountDownShort();
        document.addEventListener("DOMContentLoaded", function () {
      window.setInterval(CountDownShort, 1000);
            window.setInterval(CountDownShort, 1000);
        });
     }
     }
  }, 1000);
});
function CountDownShort() {
function CountDownShort() {
   var a = document.getElementsByClassName("CDScontainer");
   var a = document.getElementsByClassName("CDScontainer");
第18行: 第17行:
   for (var i = 0; i<a.length; i++) {
   for (var i = 0; i<a.length; i++) {
     var s = parseInt(a[i].getAttribute("data-time"), 10);
     var s = parseInt(a[i].getAttribute("data-time"), 10);
    var t = a[i].getAttribute("data-event") || ''
    if(t) {
        t = '距离'+ t + '还有'
    }
     if (s > ct) {
     if (s > ct) {
       var delta = s - ct;
       var delta = s - ct;
      var t = "";
       if (delta > 86400) {
       if (delta > 86400) {
         t += Math.floor(delta / 86400) + "天";
         t += Math.floor(delta / 86400) + "天";
第26行: 第28行:
       }
       }
       if (delta > 3600) {
       if (delta > 3600) {
         t += Math.floor(delta / 3600) + ":";
         var hour = Math.floor(delta / 3600)
        t += (hour < 10 ? '0' + hour : hour) + "";
         delta = delta % 3600;
         delta = delta % 3600;
       }
       }
       if (delta > 60) {
       if (delta > 60) {
         t += Math.floor(delta / 60) + ":";
         var minute = Math.floor(delta / 60)
        t += (minute < 10 ? '0' + minute : minute) + "";
        delta = delta % 60;
       }
       }
       if (delta > 0) {
       if (delta > 0) {
         t += delta; // 添加秒数
         t += (delta < 10 ? "0" : "") + Math.floor(delta) + "秒"; // 添加秒数
       }
       }
       a[i].innerHTML = t;
       a[i].innerHTML = t;
第43行: 第48行:
   }
   }
}
}
</script>
</script>
</includeonly><noinclude>{{documentation|content=看[[模板:倒计时/js]]}}</noinclude>
</includeonly>
<noinclude>{{documentation|content=看[[模板:倒计时/js]]}}{{#Widget:倒计时/js}}{{倒计时/js|time=2024-08-20 10:00}}</noinclude>

2024年8月18日 (日) 14:21的最新版本

Template-info.png 小工具文档  [编辑]

模板:倒计时/js