jQuery animate() method
Example
Apply an animation to an element by changing its height:
$
(
"
button
"
)
.
click
(
function
(
)
{
$
(
"
#box
"
)
.
animate
(
{
height
:
"
300px
"
}
)
;
}
)
;
Try it »
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. CSS property values change gradually, creating the animation effect.
Only numeric values can create animations (such as "margin:30px"). String values cannot create animations (such as "background-color:red").
**Tip:** Use "+=" or "-=" to create relative animations.
Syntax
(
selector
).animate(
{styles},speed,easing,callback
)
| Parameters | Description |
|---|---|
| styles | Required. Specifies one or more CSS properties/values to animate.
Note: When used with the animate() method, property names must be in camelCase: you must use paddingLeft instead of padding-left, marginRight instead of margin-right, and so on. Properties that can be animated: |
Possible values:
- Millisecond
- "slow"
- "fast"
Possible values:
- "swing" - Moves slowly at the beginning/end, and faster in the middle
- "linear" - Moves at a constant speed
如需学习更多有关 callback 的内容,请访问我们的 [jQuery Callback](jquery-callback.html) 这一章。 |
Alternate syntax
(
selector
).animate(
{styles},{options}
)
| Parameters | Description |
|---|---|
| styles | Required. Specifies one or more CSS properties/values to animate (as above). |
| options | Optional. Specifies additional options for the animation.
Possible values: |
Try it - Example
Using animate() with a callback function
How to use animate() with a callback function to repeat an animation.
jQuery effects methods