Course contentsShow
← Web Development
Lesson 2557 of 2,98246. Animation LibrariesFree lesson

Controlling Animations - Play, Pause, Reverse

Learn to control animation playback with play(), pause(), reverse(), and restart() methods.

Controlling Animations - Play, Pause, Reverse

You'll learn how to dynamically control GSAP animation playback using built-in methods for interactive experiences.

The Core Idea

Up until now, you've created animations that start automatically and play through to completion. But real interactive applications need control—think of a video player's play/pause buttons. GSAP gives every animation (and timeline) built-in methods to control playback just like media controls.

When you create an animation or timeline, GSAP returns an object with methods that let you manipulate its state. These methods work on any animation you've stored in a variable.

Essential Control Methods

play() - Starts or resumes animation playback from wherever it currently is.

pause() - Freezes the animation at its current progress. The animation stays in place, ready to resume.

reverse() - Plays the animation backwards from its current position. If the animation was playing forward, it switches direction.

restart() - Jumps back to the beginning and plays forward, regardless of where the animation was.

Practical Example

const tween = gsap.to(".box", { x: 300, duration: 2 });

// Button event handlers
document.querySelector("#pauseBtn").addEventListener("click", () => {
  tween.pause();
});

document.querySelector("#playBtn").addEventListener("click", () => {
  tween.play();
});

document.querySelector("#reverseBtn").addEventListener("click", () => {
  tween.reverse();
});

document.querySelector("#restartBtn").addEventListener("click", () => {
  tween.restart();
});

These methods work identically on timelines, letting you control complex sequences with a single command.

Key Takeaway: GSAP animations and timelines are controllable objects—use play(), pause(), reverse(), and restart() to create interactive, user-controlled animation experiences.