JavaScript倒数计时器显示nan

时间:2019-05-29 18:19:30

标签: cookies timer timeout countdowntimer

我想使计时器的倒数从10分钟变为0,这在刷新页面时一直持续,但是却得到了更多的结果。这是我的代码和我的代码笔https://codepen.io/anon/pen/XwPJMe

的链接
<div class="countdown" id="countdown1">
<span class="timeel minutes">00</span>
<span class="timeel timeRefMinutes">minutes</span>
<span class="timeel seconds">00</span>
<span class="timeel timeRefSeconds">seconds</span>
</div> 

window.onload = function() {
                  // Month Day, Year Hour:Minute:Second, id-of-element-container
                  countDownToTime("10:00", 'countdown1'); // ****** Change this line!
                }
                function countDownToTime(countTo, id) {
                  countTo = new Date(countTo).getTime();
                  var now = new Date(),
                      countTo = new Date(countTo),
                      timeDifference = (countTo - now);

                  var secondsInADay = 60 * 60 * 1000 * 24,
                      secondsInAHour = 60 * 60 * 1000;

                  mins = Math.floor(((timeDifference % (secondsInADay)) % (secondsInAHour)) / (60 * 1000) * 1);
                  secs = Math.floor((((timeDifference % (secondsInADay)) % (secondsInAHour)) % (60 * 1000)) / 1000 * 1);

                  var idEl = document.getElementById(id);
                  idEl.getElementsByClassName('minutes')[0].innerHTML = mins;
                  idEl.getElementsByClassName('seconds')[0].innerHTML = secs;

                  clearTimeout(countDownToTime.interval);
                  countDownToTime.interval = setTimeout(function(){ countDownToTime(countTo, id); },1000);
                }

0 个答案:

没有答案
相关问题