Introduction to jQuery
JQuery Syntax
JQuery Effects
JQuery HTML
JQuery Traversing
The jQuery .animate()
method is one of the most powerful tools in jQuery — it lets you create custom animations by changing CSS properties over time.
animate()
MethodThe .animate()
method allows you to gradually change CSS properties (with numeric values) using animation.
Syntax:
$(selector).animate({ properties }, speed, easing, callback);
properties
: A map of CSS properties and values to animatespeed
(optional): "slow"
, "fast"
, or milliseconds (e.g., 1000
)easing
(optional): "swing"
or "linear"
The following example demonstrates a simple use of the animate()
method; it moves a <div> element to the right, until it has reached a style property of 50px:
Try it yourself
You can pass multiple properties inside the {}
of .animate()
to animate them at the same time.
Try it yourself
You can use +=
or -=
to change CSS values relative to their current value.
Try it yourself
jQuery provides some built-in keywords that simplify common animations:
"show"
– Reveals the element with animation"hide"
– Hides the element with animation"toggle"
– Toggles between show and hide states__These keywords are especially useful with height, width, and opacity properties.
Try it yourself
By default, .animate()
uses a queue system, meaning:
___Animations are placed in a queue and executed one at a time, in the order you call them.
This helps build step-by-step animations without needing setTimeout()
or complicated logic.
Try it yourself