Timer class is the foundation for all time-based animations in Anime.js. It extends the Clock class and provides core timing functionality including playback control, looping, callbacks, and time manipulation.
Constructor
Parameters
Configuration object for the timer
Parent timeline if this timer is a child
Position within the parent timeline in milliseconds
Properties
id
String | Number
Unique identifier for the timer instance.
duration
Number
Total duration of the timer including all loops and loop delays in milliseconds.
iterationDuration
Number
Duration of a single loop iteration in milliseconds.
iterationCount
Number
Total number of loop iterations. Infinity for infinite loops.
paused
Boolean
Indicates whether the timer is currently paused.
began
Boolean
Indicates whether the timer has begun playing.
completed
Boolean
Indicates whether the timer has completed all iterations.
cancelled
Boolean
Indicates whether the timer has been cancelled. Setting to true cancels the timer, setting to false resets and plays it.
backwards
Boolean
Indicates the current playback direction.
parent
Timeline | null
Reference to the parent timeline, if any.
currentTime
Number
Current playback time in milliseconds. Can be set to seek the timer.
iterationCurrentTime
Number
Current time within the current iteration in milliseconds. Can be set to seek within the iteration.
progress
Number (0-1)
Overall progress from 0 to 1. Can be set to seek by percentage.
iterationProgress
Number (0-1)
Progress within the current iteration from 0 to 1. Can be set to seek within the iteration by percentage.
currentIteration
Number
Index of the current loop iteration (0-based). Can be set to jump to a specific iteration.
reversed
Boolean
Indicates whether the timer is playing in reverse. Setting to true reverses playback, false plays forward.
speed
Number
Playback rate multiplier. Values > 1 speed up, < 1 slow down. Inherited from Clock class.
fps
Number
Target frame rate for the timer. Inherited from Clock class.
deltaTime
Number
Time elapsed since the last tick in milliseconds. Inherited from Clock class.
Callback Properties
These properties store the callback functions and can be accessed or modified at runtime:timer.onBegin- Called when timer beginstimer.onBeforeUpdate- Called before each updatetimer.onUpdate- Called on each updatetimer.onLoop- Called on loop completiontimer.onPause- Called when pausedtimer.onComplete- Called when all iterations complete