Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between done and complete options in the jquery animate method

Tags:

jquery

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?

like image 313
A.B.Developer Avatar asked Jun 15 '13 16:06

A.B.Developer


People also ask

What is animation function in jQuery?

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").

What is the correct syntax to call the jQuery animate () function?

jQuery Animations - The animate() Method The jQuery animate() method is used to create custom animations. Syntax: $(selector). animate({params},speed,callback);

Which jQuery method is used to stop an animation before it is finished?

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).

Which of the following functions in jQuery can help create custom animations?

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.


1 Answers

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.

like image 57
Alpesh Nakrani Avatar answered Oct 20 '22 14:10

Alpesh Nakrani