stretch() V4 JS
更改动画的总持续时间和其补间动画的持续时间,以适应特定时间。
总持续时间等于一次迭代的持续时间乘以总迭代次数。因此,如果一个动画为 1000 毫秒并循环两次(总共 3 次迭代),则总持续时间将为 3000 毫秒 (1000 * 3)。
animation.stretch(duration);
参数
名称 | 类型 | 描述 |
---|---|---|
持续时间 | 数字 |
动画的新总持续时间,单位为毫秒 |
将动画 stretch 到 0
也会将其所有补间动画的持续时间设置为 0
,这将使它们在后续调用 stretch()
时具有相同的长度。
返回值
动画自身
可以与其他动画方法链式调用。
stretch() 代码示例
import { animate, utils, stagger } from 'animejs';
const [ $range ] = utils.$('.range');
const [ $totalDuration ] = utils.$('.value');
const animation = animate('.square', {
x: '17rem',
ease: 'inOutSine',
delay: stagger(200),
});
const stretchAnimation = () => {
const newDuration = +$range.value;
$totalDuration.textContent = newDuration;
animation.stretch(newDuration).restart();
}
stretchAnimation();
$range.addEventListener('input', stretchAnimation);
<pre class="large log row">
<span class="label">total duration</span>
<span class="value">0</span>
</pre>
<div class="medium row">
<div class="square"></div>
</div>
<div class="medium row">
<div class="square"></div>
</div>
<div class="medium centered row">
<fieldset class="controls">
<input type="range" min=100 max=2000 value=1000 step=100 class="seek range" />
</fieldset>
</div>