seek()
Updates the currentTime
of the timeline to a specific time.
timeline.seek(time, muteCallbacks);
Parameters
Name | Type | Description |
---|---|---|
time | Number |
The new currentTime in ms of the timeline |
muteCallbacks=false (opt) | Boolean |
If true , prevent the callbacks from being fired |
Returns
The timeline itself
Can be chained with other timeline methods.
seek() code example
import { createTimeline, utils } from 'animejs';
const [ $range ] = utils.$('.range');
const [ $playPauseButton ] = utils.$('.play-pause');
const updateButtonLabel = tl => {
$playPauseButton.textContent = tl.paused ? 'Play' : 'Pause';
}
const tl = createTimeline({
autoplay: false,
onUpdate: self => {
$range.value = self.currentTime;
updateButtonLabel(self);
},
onComplete: updateButtonLabel,
})
.add('.circle', { x: '15rem' })
.add('.triangle', { x: '15rem' }, 500)
.add('.square', { x: '15rem' }, 1000);
const seekTimeline = () => tl.seek(+$range.value);
const playPauseTimeline = () => {
if (tl.paused) {
tl.play();
} else {
tl.pause();
updateButtonLabel(tl);
}
}
$range.addEventListener('input', seekTimeline);
$playPauseButton.addEventListener('click', playPauseTimeline);
<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 centered row">
<fieldset class="controls">
<input type="range" min=0 max=2000 value=0 class="range" />
<button style="flex: 0.25;" class="button play-pause">Play</button>
</fieldset>
</div>