I know how to use a callback to wait for an animation to finish when I process the animation directly, but if the animation is called from another function, then how can I do it?
For example, I have an element, #btn, and an animation is triggered when I click it:
$('#btn').click(function() {
//bla bla...
});
Then I call it using $('#btn').click(); in another function:
function foo() {
$('#btn').click();
$('#avatar').fadeIn('slow'); //-->I want this animation to run after #btn has finished, but I don't know how to use a callback for this situation...
}
You can use
promiseanddonemethods:http://jsfiddle.net/FsyBZ/
Note that it only works when you select the element that currently is getting animated. the best option is using
animatecallback function.