onLoop V4
Executes a function every time a timeline iteration completes.
Accepts
A Function
whose first argument returns the timeline 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 { createTimeline, utils } from 'animejs';
const [ $value ] = utils.$('.value');
let loops = 0;
const tl = createTimeline({
defaults: { duration: 500 },
loopDelay: 500,
loop: true,
onLoop: self => $value.textContent = ++loops
})
.add('.circle', { x: '15rem' })
.add('.triangle', { x: '15rem' })
.add('.square', { x: '15rem' });
<div class="large row">
<div class="medium pyramid">
<div class="triangle"></div>
<div class="square"></div>
<div class="circle"></div>
</div>
<pre class="large log row">
<span class="label">loops</span>
<span class="value">0</span>
</pre>
</div>