我正在尝试编写一种游戏,你有 4 秒钟的时间(口头)回答一个问题,一旦回答完毕,就会进入下一个问题。我需要它来播放音频(不是我在这里问的),然后从 4 秒倒计时到 0,然后显示正确答案并继续。
如何创建一个从 4 秒到 0 秒的倒计时,然后转到下一件事?
我尝试了以下方法但失败了。
var counter = 4;
$('#seconds').html(counter);
function decreaseSeconds(){
counter--;
$('#seconds').fadeOut('fast');
$('#seconds').html(counter).delay(800);
$('#seconds').fadeIn('fast');
}
while ( counter > 0){
decreaseSeconds()
}
最佳答案
参见DEMO
var nextFunction = function () {
alert('Hello.');
};
sec = 4;
interval = setInterval(function () {
sec--;
document.getElementById('sec').innerHTML = sec;
if (sec == 0) {
clearInterval(interval);
nextFunction();
}
}, 1000);
关于javascript - jquery从4秒倒计时到0,然后在0处移动到下一个函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11755392/