restart()
Sets the currentTime
of a timeline to 0
and reset all properties of the elements to their initial state.
If the autoplay
parameter is set to true
, the timeline plays automatically.
Returns
The timeline itself
Can be chained with other timeline methods.
restart() code example
import { createTimeline, utils } from 'animejs';
const [ $restartButton ] = utils.$('.restart');
const tl = createTimeline({
loop: true,
alternate: true,
})
.add('.circle', { x: '15rem' })
.add('.triangle', { x: '15rem' }, 500)
.add('.square', { x: '15rem' }, 1000);
const restartTimeline = () => tl.restart();
$restartButton.addEventListener('click', restartTimeline);
<div class="large row">
<div class="medium pyramid">
<div class="triangle"></div>
<div class="square"></div>
<div class="circle"></div>
</div>
</div>
<div class="medium row">
<fieldset class="controls">
<button class="button restart">Restart</button>
</fieldset>
</div>