stretch() V4 JS
更改动画的总时长及其补间动画时长以适应特定时间。
总时长等于一次迭代的持续时间乘以总迭代次数。因此,如果一个动画是 1000 毫秒并循环两次(总共 3 次迭代),则总时长将是 3000 毫秒(1000 * 3)。
animation.stretch(duration);
参数
名称 | 类型 | 描述 |
---|---|---|
持续时间 | 数字 |
动画新的总时长(毫秒) |
将动画拉伸到 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>