loop

Defines how many times a timer repeats.

Accepts

Value Effect
Number The number of loops in the range [0, Infinity]
Infinity Loop indefinitely
true Equivalent to Infinity
-1 Equivalent to Infinity

Default

0

To change the default value globally, update the engine.defaults object.

import { engine } from 'animejs';
engine.defaults.loop = true;

loop code example

import { createTimer, utils } from 'animejs';

const [ $loops ] = utils.$('.loops');
const [ $time ] = utils.$('.time');

let loops = 0;

createTimer({
  loop: true,
  duration: 1000,
  onLoop: () => $loops.innerHTML = ++loops,
  onUpdate: self => $time.innerHTML = self.iterationCurrentTime
});
<div class="large centered row">
  <div class="col">
    <pre class="large log row">
      <span class="label">loops count</span>
      <span class="loops value">0</span>
    </pre>
  </div>
  <div class="col">
    <pre class="large log row">
      <span class="label">iteration time</span>
      <span class="time value lcd">0</span>
    </pre>
  </div>
</div>