The jQuery animate() method lets you create custom animations.
The jQuery animate() method is used to create custom animations.
Syntax:
The required params parameter defines the CSS properties to be animated.
The optional speed parameter specifies the duration of the effect. It can take the following values: "slow", "fast", or milliseconds.
The optional callback parameter is a function to be executed after the animation completes.
The following example demonstrates a simple use of the animate() method; it moves a <div> element to the left, until it has reached a left property of 250px:
| By default, all HTML elements have a static position, and cannot be moved. To manipulate the position, remember to first set the CSS position property of the element to relative, fixed, or absolute! |
Notice that multiple properties can be animated at the same time:
| Is it possible to manipulate ALL CSS properties with the animate() method? Yes, almost! However, there is one important thing to remember: all property names must be camel-cased when used with the animate() method: You will need to write paddingLeft instead of padding-left, marginRight instead of margin-right, and so on. Also, color animation is not included in the core jQuery library. If you want to animate color, you need to download the Color Animations plugin from jQuery.com. |
It is also possible to define relative values (the value is then relative to the element's current value). This is done by putting += or -= in front of the value:
You can even specify a property's animation value as "show", "hide", or "toggle":
By default, jQuery comes with queue functionality for animations.
This means that if you write multiple animate() calls after each other, jQuery creates an "internal" queue with these method calls. Then it runs the animate calls ONE by ONE.
So, if you want to perform different animations after each other, we take advantage of the queue functionality:
The example below first moves the <div> element to the right, and then increases the font size of the text:
For a complete overview of all jQuery effects, please go to our jQuery Effect Reference.
The perfect solution for professionals who need to balance work, family, and career building.
More than 10 000 certificates already issued!
The HTML Certificate documents your knowledge of HTML.
The HTML5 Certificate documents your knowledge of advanced HTML5.
The CSS Certificate documents your knowledge of advanced CSS.
The JavaScript Certificate documents your knowledge of JavaScript and HTML DOM.
The jQuery Certificate documents your knowledge of jQuery.
The XML Certificate documents your knowledge of XML, XML DOM and XSLT.
The ASP Certificate documents your knowledge of ASP, SQL, and ADO.
The PHP Certificate documents your knowledge of PHP and SQL (MySQL).
Your message has been sent to W3Schools.