seek()
Updates the currentTime
of the timer and advances it to a specific time.
timer.seek(time, muteCallbacks);
Parameters
Name | Type | Description |
---|---|---|
time | Number |
The new currentTime in ms of the timer |
muteCallbacks=false (opt) | Boolean |
If true , prevent the callbacks from being fired |
Returns
The timer itself
Can be chained with other timer methods.
seek() code example
import { createTimer, utils } from 'animejs';
const [ $range ] = utils.$('.range');
const [ $playPauseButton ] = utils.$('.play-pause');
const [ $time ] = utils.$('.time');
const updateButtonLabel = timer => {
$playPauseButton.textContent = timer.paused ? 'Play' : 'Pause';
}
const timer = createTimer({
duration: 2000,
autoplay: false,
onUpdate: self => {
$range.value = self.currentTime;
$time.innerHTML = self.currentTime;
updateButtonLabel(self);
},
onComplete: updateButtonLabel,
});
const seekTimer = () => timer.seek(+$range.value);
const playPauseTimer = () => {
if (timer.paused) {
timer.play();
} else {
timer.pause();
updateButtonLabel(timer);
}
}
$range.addEventListener('input', seekTimer);
$playPauseButton.addEventListener('click', playPauseTimer);
<div class="large centered row">
<div class="half col">
<pre class="large log row">
<span class="label">current time</span>
<span class="time value lcd">0</span>
</pre>
</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>