编辑:在此处添加小提琴:http: //jsfiddle.net/jnS3H/12/与您的代码和修复。
要执行间隔计时器,您可以执行以下操作:
//create a function to handle the auto rotate
function autoRotate() {
//code here for what happens every n seconds
}
//create a function that holds the interval to do an auto rotate push
function rotate(){
var startRotate = setInterval(function(){ //Start the autorotate on load to rotate every 2 seconds.
autoRotate();
}, 2000);
}
$('.rightarrow, .leftarrow').click(function(){
clearInterval(startRotate); //Stops the auto-animation
clearTimeout(startAgain); //Stops the starting again - incase you click again, it resets the timeout
//write some code here to do something when you click on the right arrow
var startAgain = setTimeout(function(){ //Then create a timeout to start rotating again after you click
rotate();
}, 2000);
});
$(document).load(function(){
rotate();
});
当然这是非常松散的代码,你必须填空并测试它,但我相信主体是正确的。