jQuery animate()Method
Examples
Apply an animation to an element by changing its height:
Try it Yourself »
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 using CSS styles. The CSS property values are gradually changed, thus creating an animation effect.
Only numeric values can be animated (e.g., "margin:30px"). String values cannot be animated (e.g., "background-color:red").
Tip:Use "+=" or "-=" to create relative animations.
Syntax
| Parameter | Description |
|---|---|
| styles | Required. Specifies one or more CSS properties/values to be animated. Note:When used with the animate() method, property names must be written in camelCase: You must use paddingLeft instead of padding-left, marginRight instead of margin-right, and so on. Animatable properties:
|
| speed | Optional. Specifies the speed of the animation. Possible values:
|
| easing | Optional. Specifies the speed of the element at different points in the animation. Default value is "swing". Possible values:
|
| callback | Optional. A function to be executed after the animate function has finished. To learn more about callback, please visit ourjQuery Callbackthis chapter. |
Alternate Syntax
| Parameter | Description |
|---|---|
| styles | Required. Specifies one or more CSS properties/values to be animated (same as above). |
| options | Optional. Specifies extra options for the animation. Possible values:
|
Try it Yourself - Examples
Using animate() with a callback function
How to use animate() with a callback function to repeat animations.
Other Extensions
jQuery Effects Methods