setTimeout只运行一次? [英] setTimeout runs only once?
本文介绍了setTimeout只运行一次?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
function slide()
{
if($('.current').is(':last-child')){
$('.current').removeClass('.current');
$('#imgholder').first().addClass('.current');
$('#imgholder').animate({left: '3920px'});
}
else{
$nxt=$(".current");
$(".current").removeClass("current");
$nxt.next().addClass("current");
$('#imgholder').animate({left: '-=980'},{duration: 'slow', easing: 'easeOutBounce' });
}
}
var loop_handle= setTimeout("slide()",'3000');
我已将此代码放在标题部分,而setTimeout只运行一次
I have put this code in header section and the setTimeout runs only once
plz help
plz see
http:// www。 beta.storeji.in/
plz help plz see http://www.beta.storeji.in/
推荐答案
setTimeout
应该只运行一次。您正在寻找 setInterval
。
setTimeout
should only run once. You're looking for setInterval
.
var loop_handle = setInterval(slide, 3000);
此外,第二个参数应该是数字,而不是字符串。当函数调用不需要任何参数时,最好引用函数而不是使用字符串。字符串将转换为函数。此函数将在窗口范围内执行。
Also, the second argument should be a number, not a string. When the function call doesn't require any arguments, it's better to reference to the function instead of using a string. A string would be converted to a function. This function will be executed within the scope of the window.
setInterval("slide()", 3000);
//becomes
setInterval(Function("slide();"), 3000);
这篇关于setTimeout只运行一次?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文