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 );
精彩评论