Reputation: 1
$(function(){
$('.fadein img:gt()').hide();
setInterval(function(){
$('.fadein :first-child').fadeOut()
.next('img').fadeIn()
.end().appendTo('.fadein');},
6800);
});
I'm hoping to stop this onclick of a button and start it on click of same button. any ideas?
Upvotes: 0
Views: 697
Reputation: 26930
Try this:
$(function(){
$('.fadein img:gt()').hide();
var active = true;
setInterval(function(){
if(active) {
$('.fadein :first-child').fadeOut()
.next('img').fadeIn()
.end().appendTo('.fadein');
}
}, 6800);
$('#buttonId').click(function(){ active = !active; });
});
Thanks to Rikonator, here is better answer:
$(function(){
$('.fadein img:gt()').hide();
var active = true;
var interval = setInterval(intervalFunction, 6800);
$('#buttonId').click(function(){
if(!active)
interval = setInterval(intervalFunction, 6800)
else
clearInterval(interval);
});
function intervalFunction(){
$('.fadein :first-child').fadeOut()
.next('img').fadeIn()
.end().appendTo('.fadein');
}
});
Upvotes: 1