Reputation: 1
I have 5 slides, which are changing after 5 second or on mouse click(Done with SetInterval function, which triggers 'click')
Problem is following, for example: Lets say it's set to #slide_1, when 4 seconds passed and i manually click on #slide_2, next slide(#slide_3) comes active after 1 second. It's all SetInterval, that triggers click and i have no idea how to add 5 second interval again, between manual and SetInterval clicks..
Here is my code,
setInterval(function() {
if(!$('.buttons > ul ').children('.butt_press').next().length){
$('.buttons > ul').children(':first').trigger('click');
}
else{
$('.buttons > ul').children('.butt_press').next().trigger('click');
}
}, 5500);
thanks
Upvotes: 0
Views: 87
Reputation: 18557
setInterval
returns an interval id which you can use to clear the interval and then re-create it.
var nextSlide = function () {
if(!$('.buttons > ul ').children('.butt_press').next().length){
$('.buttons > ul').children(':first').trigger('click');
} else {
$('.buttons > ul').children('.butt_press').next().trigger('click');
}
};
var interval = setInterval(nextSlide, 5000);
$('some_selector').on('click', function () {
nextSlide();
clearInterval(interval);
interval = setInterval(nextSlide, 5000);
});
Upvotes: 1