Controller

The Controller class is the foundation of all Animatry animations. Both Tween and Timeline extend from it.
It handles animation progress, repetition, alternation, delay, and lifecycle events.

Basic Lifecycle

A Controller manages animation state over time. The most common methods include .play(), .pause(), .reverse(), and .seek().

const controller = animatry.to('.box', {
x: 300,
duration: 1,
paused: true,
});
controller.play(); // start the animation
controller.pause(); // pause it
controller.seek(0.5); // jump to 50%
controller.reverse(); // play it backward

Progress Control

You can precisely control how far an animation has progressed. There are multiple levels of progress tracking:

  • .progress() – progress of the current iteration (0 to 1)
  • .totalProgress() – progress of the full animation including repeats
  • .elapsed() – time passed in seconds
controller.progress(0.25); // jump to 25% of one iteration
controller.totalProgress(0.75); // jump to 75% including repeats
controller.elapsed(0.5); // jump to 0.5s into the animation

Repeats, Alternation, and Delay

Animations can repeat, alternate direction, and include delays between repeats.

animatry.to('.box', {
x: 300,
repeat: 2,
alternate: true,
delay: 0.5,
iterationDelay: 0.2,
});

Callbacks

Controllers support event hooks to execute logic at key points in the animation lifecycle.

controller
.onStart(() => console.log('started'))
.onComplete(() => console.log('completed'))
.onReverseStart(() => console.log('reversed'))
.onReverseComplete(() => console.log('reverse completed'))
.onRepeat(() => console.log('repeating'))
.onUpdate(() => console.log('updated'));

Configuration API

Method
Description
.play()
Starts or resumes the animation.
.pause()
Pauses the animation.
.reverse()
Plays the animation in reverse.
.restart()
Resets and starts the animation from the beginning.
.seek(time)
Jumps to a specific time in seconds.
.progress(value)
Gets or sets the progress of the current iteration (0 to 1).
.elapsed(value)
Gets or sets the elapsed time (in seconds) of the current iteration.
.totalProgress(value)
Gets or sets total progress (across repeats).
.totalElapsed(value)
Gets or sets total elapsed time (including repeats).
.repeat(count)
Sets how many times the animation should repeat. -1 for infinite.
.alternate(bool)
Toggles alternation of direction on each repeat.
.delay(seconds)
Sets the initial delay before starting.
.iterationDelay(seconds)
Sets delay between repeats.
.timeScale(factor)
Changes speed of animation (1 = normal speed).
.reversed()
Returns whether the animation is currently reversed.
.isPlaying()
Returns whether the animation is currently active.
.onStart(callback)
Fires when the animation starts (from 0).
.onComplete(callback)
Fires when the animation reaches 100%.
.onReverseStart(callback)
Fires when reversed animation starts.
.onReverseComplete(callback)
Fires when reversed animation reaches 0%.
.onRepeat(callback)
Fires when a repeat cycle begins.
.onUpdate(callback)
Fires on every animation frame.