我是编码新手,所以我的代码有点混乱。因此,我正在制作一个5分钟的倒数计时器,它确实进行倒数计时,但它似乎跳过了一些数字或出现了奇怪的延迟。为什么是这样? 这是链接https://jsfiddle.net/m82ube1y/9/
var timer= document.getElementById("timer").children;
var edDate = new Date();
var endDate = edDate.setMinutes(edDate.getMinutes()+5) ;
setInterval(time, 1000);
function time() {
var currentDate = new Date().getTime();
var countdowntime = endDate-currentDate;
var days = Math.floor((((countdowntime/1000)/60)/60)/24);
var hours = Math.floor((((countdowntime/1000)/60)/60))%24;
var minutes = Math.floor(((countdowntime/1000)/60))%60;
var seconds = Math.floor((countdowntime/1000))%60;
timer[0].textContent = days;
timer[1].textContent = hours;
timer[2].textContent = minutes;
timer[3].textContent = seconds;
timer[3].classList.add("rotate");
setTimeout(function(){f(3);},500);
function f(x){timer[x].classList.remove("rotate")}
if(timer[3].textContent==59){
timer[2].classList.add("rotate");
setTimeout(function(){f(2);},500);}
}
编辑:我发现它在Firefox中可以正常工作,但在chrome中不能正常工作。仍然不明白为什么。