开发者

ClearInterval with a click

I have been working within another question on this site and have almost completed what I need to accomplish. I have 30 divs that slide in and out on an interval. What I am trying to achieve is that when an anchor within each of these divs is clicked it should stop the rotation.

In the other question page it has开发者_如何学编程 been suggested that I use clearInterval but I am unable to get it to work. More details are here: Sliding through divs at interval - jQuery - Stack Overflow

If anyone has any advice, explanation, or a simple example - I would greatly appreciate it.

Thanks in advance!!


setInterval() returns an identifier that you need to store in order to properly cancel it with clearInterval().

// Alert 'hi' every second
var interval = setInterval( function()
{
  alert( 'hi' );
}, 1000 );

// But cancel after 5 seconds
setTimeout( function()
{
  clearInterval( interval );
}, 5100 );
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜