Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get jQuery to wait until an effect is finished?

Tags:

jquery

I am sure I read about this the other day but I can't seem to find it anywhere.
I have a fadeOut() event after which I remove the element, but jQuery is removing the element before it has the chance to finish fading out.
How do I get jQuery to wait until the element had faded out, then remove it?

like image 468
uriDium Avatar asked Jun 30 '09 20:06

uriDium


People also ask

How to set delay in jQuery?

jQuery delay() Method The delay() method sets a timer to delay the execution of the next item in the queue.

How to call function with delay in jQuery?

To call a jQuery function after a certain delay, use the siteTimeout() method. Here, jQuery fadeOut() function is called after some seconds.

What is STOP () in jQuery?

The jQuery stop() method is used to stop an animation or effect before it is finished. The stop() method works for all jQuery effect functions, including sliding, fading and custom animations.

What is $$ in jQuery?

$ sign is just a valid javascript identifier which is used as an alias for jQuery. Prototype, jQuery, and most javascript libraries use the $ as the primary base object (or function). Most of them also have a way to relinquish the $ so that it can be used with another library that uses it.


1 Answers

With jQuery 1.6 version you can use the .promise() method.

$(selector).fadeOut('slow'); $(selector).promise().done(function(){     // will be called when all the animations on the queue finish }); 
like image 86
Reinaldo Junior Avatar answered Sep 21 '22 06:09

Reinaldo Junior