2011-05-18 94 views
0

我使用有机标签和图像旋转器的网格。当用户点击其中一个缩略图时,图像旋转器将停止自动前进。当用户点击一个标签时,自动提前重新开始。但是,如果没有超时或暂停,当用户单击选项卡时,自动提前可能会同时发生变化。jQuery:触发后超时()

jQuery代码:

current=-1; 
$('.years li:first a', tab).trigger('click',[true]); 
current=1; 

电流被用作标志。当它是-1时,自动提前功能将返回false。如何在将电流设置为1之前添加延迟?我在想这样的事:

$('.years li:first a', tab).trigger('click',[true]).setTimeout(function(){current=1},1000); 

但这显然不起作用。

回答

0

setTimeout不是jQuery,因此不能与jQuery对象链接。如果你分开那setTimeout你应该没问题。

此外,如果用户在设置当前值之前再次停止旋转,您可能需要清除该超时。所以你会想要做这样的事情:

var timer; 

... 

timer = setTimeout(...); 

... 

// when the rotation is stopped, clear the timer in case it hasn't triggered yet 
clearTimeout(timer);