如何使 setTimeout 函数连续循环?
例如
setTimeout(function(){
$(".slide2").hide();
$(".slide").show();
setTimeout(function(){
$(".slide").hide();
$(".slide2").show();
}, 1000);
}, 1000);
最佳答案
setInterval
实际上是邪恶的,如果 setInterval 中的代码花费的时间比您设置的时间长,它将在函数完成搞砸一切之前创建另一个进程。所以选择setTimeout
其实更好。
要使函数在 setTimeout
中循环,请使用以下语法:
function function1() {
console.log({} + [] + " = {} + []"); // run this it is actually funny
}
function runner() {
function1();
setTimeout(function() {
runner();
}, time);
}
runner();
关于javascript - 如何使 setTimeout 函数连续循环?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17126758/