jQuery Effect - animate() Method
Example
Change the height of the "div" element:
$(".btn1").click(function(){ $("#box").animate({height:"300px"}); });
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 through CSS styles. The CSS property values change gradually, creating the animation effect.
Only numeric values can create animations (e.g., "margin:30px"). String values cannot create animations (e.g., "background-color:red").
Note:Use "+=" or "-=" to create relative animations (relative animations).
Syntax 1
$(selector).animate(styles,speed,easing,callback)
Parameters | Description |
---|---|
styles |
Required. Specifies the CSS styles and values that create the animation effect. Possible CSS style values (with examples):
Note:CSS styles use DOM names (e.g., "fontSize") to set, not CSS names (e.g., "font-size"). |
speed |
Optional. Specifies the animation speed. The default is "normal". Possible values:
|
easing |
Optional. Specifies the easing function to set the animation speed at different animation points. Built-in easing functions:
Extended plugins provide more easing functions. |
callback |
Optional. The function to be executed after the animate function is executed. For more information about callbacks, please visit our jQuery Callback This chapter. |
Syntax 2
$(selector).animate(styles,options)
Parameters | Description |
---|---|
styles | Required. Specifies the CSS styles and values that produce the animation effect (as above). |
options |
Optional. Specifies additional options for the animation. Possible values:
|