Today when I was reading new features of the jQuery .animate()
method in the options of it I faced two options that I think have the same action.
These options are done
and complete
. According to docs they are functions that run when the animation completes.
complete
Type: Function()
A function to call once the animation is complete.
and :
done
Type: Function( Promise animation, Boolean jumpedToEnd )
A function to be called when the animation completes (its Promise object is resolved). (version added: 1.8)
Now my question is what is the difference between the two?
Definition and Usage. The animate() method performs a custom animation of a set of CSS properties. This method changes an element from one state to another with CSS styles. The CSS property value is changed gradually, to create an animated effect. Only numeric values can be animated (like "margin:30px").
jQuery Animations - The animate() Method The jQuery animate() method is used to create custom animations. Syntax: $(selector). animate({params},speed,callback);
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. Syntax: $(selector).
The jQuery animate() method is used to create custom animations. The animate() method is typically used to animate numeric CSS properties, for example, width , height , margin , padding , opacity , top , left , etc.
JQuery uses promise which means at the time of done JavaScript can go to next function from promise.
Let's say you have written go to foo and go to bar functions. JQuery will start second one after first started execution irrespective of completion of first.
So when you implement promise, it will wait for previous to complete.
Finally in your case, complete will be called once done is done :). So if you want to process once animation is completed and again do some tricks when first trick is completed write it in complete.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With