Timer V4

Schedules and controls timed callbacks that can be used as an alternative to setTimeout() or setInterval(), keeping animations and callbacks synchronized.

Timers are created using the createTimer() method imported from the main 'animejs' module:

import { createTimer } from 'animejs';

const timer = createTimer(parameters);

Or imported as a standalone module from the 'animejs/timer' subpath:

import { createTimer } from 'animejs/timer';

Parameters

Name Accepts
parameters (opt) An Object of Timer playback settings and Timer callbacks

Returns

Timer

Timer code example

import { createTimer } from 'animejs';

const [ $time, $count ] = utils.$('.value');

createTimer({
  duration: 1000,
  loop: true,
  frameRate: 30,
  onUpdate: self => $time.innerHTML = self.currentTime,
  onLoop: self => $count.innerHTML = self._currentIteration
});
<div class="large centered row">
  <div class="half col">
    <pre class="large log row">
      <span class="label">current time</span>
      <span class="value lcd">0</span>
    </pre>
  </div>
  <div class="half col">
    <pre class="large log row">
      <span class="label">callback fired</span>
      <span class="value lcd">0</span>
    </pre>
  </div>
</div>