javascript,jquery,for-loop,settimeout,cleartimeout
You need to pass a function as an argument to setTimeout. Try this: timer = setTimeout(function() { switchBG(index); }, 10000); Doing setTimeout(switchBG(index), 10000); basically evaluates switchBG(index) and passes its return value (which is currently undefined) to setTimeout....
javascript,jquery,ajax,settimeout,cleartimeout
The timer variable is scoped to your success function, so it's always null when your code to clear the old timeout is reached. Move the declaration of timer outside your AJAX call, and it should work. var timer = null; $.ajax({ beforeSend: function() { ... }, success: function(data) { if(timer)...
javascript,jquery,jquery-animate,settimeout,cleartimeout
I've played around with setTimeout and setInterval but I think it's better to use a recursive call in the done callback of jQuery animate. Also stopping is then pretty easy with $('.plwid').stop();. Please find the demo below and here at JSFiddle. function tomove() { $('.plwid').animate({ left: '+=10' }, 100, 'linear',...
javascript,jquery,settimeout,cleartimeout
You have to tell the script if the message is already showing or not, that way you avoid the multiple delays. Below is a working version of what I'm talking about. I hope that helps. var scrollHeight = 15; var message = $( ".message" ); var messagestatus = false; var...
javascript,settimeout,multiple-instances,scoping,cleartimeout
Finally made it to work. For posterities... var starr = [ 'bloop the boop', 'cammy the shadow', 'i like cauliflower', 'bro, i kick u hard', 'like measels? I dont.', 'eat fish and pie' ]; var writer = function(){ var timer; this.writeStat = function(str,dest) { var options = { "step" :...