by
82k 39
6
8
6,228
16
Top 1% !
Popular
Famous
Pearl of Wisdom
Nice
Easy-to-find
Specified
OpenSource
Popularity: 1101st place
Frameworkjquery
Languagejavascript
LicenseMIT_X11
TechnologyAJAX
TechnologyJQuery

Using promise() with JQuery animate

With jQuery 1.5 the $.ajax implements the Promise interface. So you can use done() fail() and always() on the returned promise object returned from the ajax call.

You can do the same when invoking the animate() function.
The animate function returns the collection of elements the animate() is acting on, so you can create the promise explicitly and observe when all actions bound to that collection have finished.

See this example:
Copy Embed Code
<iframe id="embedFrame" style="width:600px; height:300px;"
src="https://www.snip2code.com/Embed/213479/Using-promise()-with-JQuery-animate?startLine=0"></iframe>
Click on the embed code to copy it into your clipboard Width Height
Leave empty to retrieve all the content Start End
// Shows an alert at the end of an animation. $('#myElement').animate( { height: 200 + 'px'}, 500) .promise() .done( function () { alert('Animation complete!'); });
If you want to be updated about similar snippets, Sign in and follow our Channels

blog comments powered by Disqus