jquerydelaysettimeoutjquery-animate

jQuery delay() - how to stop it?


I already tried stop(true,true), stop(true) and clearQueue(); but this doesn't work.

I have problem with fast changing slides, i already have some function what have to reset everything, but it doesn't work.

function reset(){
   $('div').clearQueue();
   $('#img').html('').css({'left':0,'right':0,'opacity':1,'z-index':1});
   $('#img2').html('').css({'left':0,'right':0,'opacity':1,'z-index':1});
   $('#place').html('');$('#place').html('<div id="img"></div><div id="img2"></div>');
}

But i thing this doesn't stop (or delete) delay() function on animations. So I don't know if i don't have to use setTimeout function.

Here is piece of animation script:

reset();
actual_slide=2;
  $('#img').html('<img src="'+image[4]+'" alt="Obrázek">').css({'opacity':0,'z-index':2}).delay(time_delay/5).fadeTo(time_fast,1).delay(time_delay*2).fadeTo(time_fast,0);
  $('#img2').html('<img src="'+image[3]+'" alt="Obrázek">').css({'opacity':'0','top':0}).fadeTo(time_fast,1).animate({'top':'-495'},time_delay*3,function(){
    if(actual_slide==2){$('#img2').css({'top':0}).fadeTo(time_fast*2,0).html('');}else{reset();}
    if(actual_slide==2){$('#img').html('<img src="'+image[3]+'" id="1" alt="Obrázek">').fadeTo(time_fast*2,'1').css({'left':-300,'top':-700}).animate({'left':-900,'top':-700},time_delay*2);}else{reset();}
    if(actual_slide==2){$('#1').css({'width':1365,'height':1200}).animate({'width':1665,'height':1400},time_delay*2);}else{reset();}
  });                          

That actual_slide have to protect it before repeating that function, but that doesn't work too.. Problem is when i fast changing slides, because that reset doesn't stop everything, and it start doing things what i don't want to have in (like change picture to other and other).


Solution

  • From the jQuery delay page:

    The .delay() method is best for delaying between queued jQuery effects. Because it is limited—it doesn't, for example, offer a way to cancel the delay—.delay() is not a replacement for JavaScript's native setTimeout function, which may be more appropriate for certain use cases.

    Take a look at the doTimeout plugin; it may be what you are looking for.

    I hope this helps!