Core Module
Timer
The Timer module provides precise timing control and is the foundation of all animation playback in SZZ Labs.
createTimer()
Create a timer that ticks on every frame or at a specified interval.
import { createTimer } from 'animejs'; const timer = createTimer({ duration: 2000, loop: true, onUpdate(self) { console.log(self.currentTime); }, onComplete() { console.log('Done!'); } });
Properties
| Property | Default | Description |
|---|---|---|
| duration | 1000 | Duration in milliseconds |
| delay | 0 | Delay before the timer starts |
| loop | false | Loop the timer indefinitely or N times |
| reversed | false | Play the timer in reverse |
| autoplay | true | Start automatically on creation |
| frameRate | 60 | Target frame rate for the timer |
Callbacks
- onBegin — fired once when the timer starts for the first time
- onUpdate — fired on every animation frame
- onLoop — fired each time the timer loops
- onComplete — fired when the timer finishes all iterations
Methods
// Control playback timer.play(); timer.pause(); timer.restart(); timer.seek(500); // Seek to 500ms timer.reverse();