Search code examples
jqueryanimationdeque

How to stop an animation that is queued using jquery.timing plugin


How do you stop an animation that is queued using this plugin

This is how I queue the fadeOut():

$('#myDiv').wait(2000).fadeOut("slow");

This doesn't work:

$('#myDiv').stop(true, true).clearQueue().show();


Solution

  • First, jQuery has deprecated .wait() in favor of the .delay() function. There is no existing documentation for .wait() on the jQuery API site. As shown in the jQuery documentation, there is no built-in way to cancel a .delay() function once it's been called. A better alternative would be to simply use vanilla Javascript's built-in timer function (MDN documentation) setTimeout(), and its canceling partner clearTimeout().

    EDIT: Using the plugin's .wait() function, you could cancel the set timer using $.unwait().