js多个倒计时并存

Tips:You can change the code before run.

到毫秒

//倒计时
 function countDown(time, fn) {
    var maxtime = (new Date(time) - new Date()) / 10;//剩余秒
    var timer = setInterval(function () {
      if (maxtime >= 0) {
            var dd = parseInt(maxtime /100/ 60 / 60 / 24, 10);//计算剩余的天数
            var hh = parseInt(maxtime /100/ 60 / 60 % 24, 10);//计算剩余的小时数
            var mm = parseInt(maxtime /100/ 60 % 60, 10);//计算剩余的分钟数
            var ss = parseInt(maxtime /100% 60, 10);//计算剩余的秒数
            var hm = parseInt(maxtime % 100, 10);//计算剩余的毫秒数
            hh = checkTime(hh);
            mm = checkTime(mm);
            ss = checkTime(ss);
            hm = checkTime(hm);
            msg = hh + ":" + mm + ":" + ss + ":" + hm;
            fn(msg);
            --maxtime;
          }
          else {
            clearInterval(timer);
            fn("已结束");
          }
        }, 10);
  }
  function checkTime(i) {
    if (i < 10) {
      i = "0" + i;
    }
    return i;
  };

Tips:You can change the code before run.

THE END
分享
二维码
打赏
< <上一篇
下一篇>>