JQuery setInterval with pause on hover -


i trying multiple divs fade in , fade out. on hover, pause animation. on hover out, continue animation. right i've gotten far, divs fade in , out correctly, , on hover stops. when hover out, animation doesn't start again. suggestions i'm doing wrong?

var timer; $(document).ready(function(){     $(function starttimer(){         $('#quotes .textitem:gt(0)').hide();         timer = setinterval(function(){$('#quotes > :first-child').fadeout().next('div').fadein().end().appendto('#quotes');}, 1000);     });      $('#quotes').hover(function (ev) {         clearinterval(timer);     }, function (ev) {         starttimer();     }); });  

here jfiddle:

try this

var timer; $(document).ready(function(){     timer = function(){$('#quotes > :first-child').fadeout().next('div').fadein().end().appendto('#quotes');};     $('#quotes .textitem:gt(0)').hide();     var interval = setinterval(timer , 2000); $('#quotes').hover(function (ev) {     clearinterval(interval); }, function (ev) {     interval = setinterval(timer , 2000); }); });  

demo here


Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -