stretch()
Changes the total duration of a timer to fit a specific time.
The total duration is equal to the duration of an iteration multiplied with the total number of iterations. So if a timer has a duration of 1000ms and loops twice (3 iterations in total), the total duration is 3000ms (1000 * 3).
timer.stretch(duration);
Parameters
Name | Type | Description |
---|---|---|
duration | Number |
The new total duration in ms of the timer |
Returns
The timer itself
Can be chained with other timer methods.
stretch() code example
import { animate, utils } from 'animejs';
const [ $range ] = utils.$('.range');
const [ $duration ] = utils.$('.duration');
const [ $time ] = utils.$('.time');
const timer = createTimer({
duration: 2000,
onUpdate: self => $time.innerHTML = self.currentTime
});
const stretchTimer = () => {
timer.stretch(+$range.value);
$duration.innerHTML = utils.round(timer.duration, 0);
timer.restart();
}
$range.addEventListener('input', stretchTimer);
<div class="large centered row">
<div class="col">
<pre class="large log row">
<span class="label">duration</span>
<span class="duration value">2000</span>
</pre>
</div>
<div class="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 row">
<fieldset class="controls">
<input type="range" min=0 max=4000 value=2000 step=100 class="range" />
</fieldset>
</div>