onLoop
Executes a function every time a timer iteration completes.
Accepts
A Function
whose first argument returns the timer itself
Default
noop
To change the default value globally, update the engine.defaults
object.
import { engine } from 'animejs';
engine.defaults.onLoop = self => console.log(self.id);
onLoop code example
import { createTimer, utils } from 'animejs';
const [ $loops ] = utils.$('.loops');
const [ $time ] = utils.$('.time');
let loops = 0;
createTimer({
loop: true,
duration: 1000,
onLoop: self => $loops.innerHTML = ++loops,
onUpdate: self => $time.innerHTML = self.iterationCurrentTime,
});
<div class="large row">
<div class="col">
<pre class="large log row">
<span class="label">loops</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>