Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to know when a jquery effect ends if there are mutiple elements which are animated

Given the following example: If 5 <li> elements are found, the callback fires an alert 5 times...

Is there an easy way to find out when the animation is really over and just fire once?

$(this).parent().siblings('li').slideUp(500,function(){
    alert 
});
like image 453
Jurudocs Avatar asked Feb 22 '23 04:02

Jurudocs


1 Answers

$.when($(this).parent().siblings('li').slideUp(500))
 .then(function() {
            alert('Finished!');
       });

Working DEMO

when docs:

Description: Provides a way to execute callback functions based on one or more objects, usually Deferred objects that represent asynchronous events.

like image 198
gdoron is supporting Monica Avatar answered Mar 04 '23 20:03

gdoron is supporting Monica