Skip to main content
The Timeline class is the core class for creating complex animation sequences in Anime.js. It extends the Timer class and provides methods to add, synchronize, and control multiple animations along a shared timeline.

Constructor

Timeline(parameters?)

Creates a new Timeline instance.
parameters
TimelineParams
default:"{}"
Optional configuration object for the timeline
// Create a timeline with default parameters
const tl = new Timeline({
  id: 'myTimeline',
  loop: true,
  defaults: {
    duration: 1000,
    ease: 'outQuad'
  },
  onComplete: (timeline) => {
    console.log('Timeline completed');
  }
});

Properties

id

id
String | Number
Unique identifier for the timeline instance.

duration

duration
Number
Total duration of the timeline in milliseconds, including all loops. This value automatically updates as children are added.

iterationDuration

iterationDuration
Number
Duration of a single iteration (loop) of the timeline in milliseconds.

labels

labels
Record<String, Number>
Object containing named position labels. Used for positioning animations at specific named points in the timeline.
tl.label('scene1', 0)
  .label('scene2', 2000)
  .add(targets, params, 'scene1') // Position at scene1 label
  .add(targets2, params2, 'scene2'); // Position at scene2 label

defaults

defaults
DefaultsParams
Default parameters inherited by all child animations added to the timeline.

composition

composition
Boolean
Indicates whether the timeline automatically composes animations as they’re added.

onRender

onRender
Callback<Timeline>
Callback function invoked when the timeline renders.

Inherited Properties

The Timeline class inherits all properties from the Timer class, including:
  • currentTime - Current playback position in milliseconds
  • progress - Current playback progress (0-1)
  • iterationCurrentTime - Current time within the current iteration
  • iterationProgress - Progress within the current iteration (0-1)
  • currentIteration - Current loop iteration index
  • paused - Whether the timeline is paused
  • began - Whether the timeline has begun playing
  • completed - Whether the timeline has completed
  • cancelled - Whether the timeline has been cancelled
  • reversed - Whether the timeline is playing in reverse
  • speed - Playback speed multiplier
  • iterationCount - Total number of iterations

Factory Function

createTimeline(parameters?)

Convenience factory function that creates and initializes a Timeline instance.
parameters
TimelineParams
Optional timeline configuration parameters.
returns
Timeline
An initialized Timeline instance ready to play.
import { createTimeline } from 'animejs';

const tl = createTimeline({
  loop: true,
  defaults: {
    duration: 1000,
    ease: 'outExpo'
  }
});

// Equivalent to:
const tl2 = new Timeline({ /* ... */ }).init();

See Also

Build docs developers (and LLMs) love