</>
Skip to content
jQuery lessons (11/39)

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

PropertyAnimated?
widthYes
heightYes
leftYes (positioned)
topYes (positioned)
opacityYes
font-sizeYes
colorNo (use jQuery UI)
background-colorNo (use jQuery UI)

Mini Practice

  1. Animate an element's position
  2. Chain multiple animations
  3. Use relative values with +=
  4. 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.