jQuery — Animate
Basic animate()
$("div").animate({
left: "250px",
opacity: 0.5,
height: "150px",
width: "150px"
}, 1000);
Multiple Properties
$("div").animate({
left: "200px",
top: "100px",
opacity: 0.8
}, 1500);
Relative Values
// Use += or -= for relative changes
$("div").animate({
left: "+=50px",
top: "+=25px"
}, 500);
Queue Animations
$("div")
.animate({ left: "200px" }, 500)
.animate({ top: "100px" }, 500)
.animate({ opacity: 0.5 }, 500);
Easing
$("div").animate(
{ left: "200px" },
1000,
"swing" // "linear" or "swing"
);
stop() with Animations
$("div").click(function() {
$(this).stop().animate({ left: "+=100px" }, 500);
});
Chaining with animate()
$("div")
.animate({ width: "300px" }, 500)
.animate({ height: "200px" }, 500)
.animate({ opacity: 0.5 }, 500);
Animated Properties
| Property | Animated? |
|---|---|
| width | Yes |
| height | Yes |
| left | Yes (positioned) |
| top | Yes (positioned) |
| opacity | Yes |
| font-size | Yes |
| color | No (use jQuery UI) |
| background-color | No (use jQuery UI) |
Mini Practice
- Animate an element's position
- Chain multiple animations
- Use relative values with +=
- Stop an animation mid-way
Up Next
Continue with Stop — stopping animations gracefully.
Related Topics
Frequently Asked Questions about Animate
What is Animate in jQuery?
Animate is a fundamental concept in jQuery. This lesson explains it step by step with clear examples, making it easy for beginners to understand.
How do I learn Animate?
Start by reading the explanation above, then try the code examples. Practice by modifying the examples and experimenting with different values. Hands-on practice is the best way to learn Animate.
Why is Animate important in jQuery?
Animate is essential for jQuery development. Understanding this concept will help you write better code and solve real-world problems more effectively.