添加动画
可以使用 add() 方法或 sync() 方法将动画添加到时间线。
动画创建
使用 add() 方法直接创建并添加到时间线的动画。
这允许动画值与时间线现有的子动画进行组合。
timeline.add(targets, parameters, position);
参数
| 名称 | 接受 |
|---|---|
| targets | 目标 |
| 参数 | 一个包含可动画属性、补间参数、播放设置和动画回调的Object。 |
| 位置 (可选) | 时间位置 |
动画同步
使用 sync() 方法将现有动画与时间线同步。
动画值组合在动画创建时处理,并且不会影响时间线现有的子动画。
const animation = animate(target, { x: 100 });
timeline.sync(animation, position);
参数
| 名称 | 接受 |
|---|---|
| 动画 | 动画 |
| 位置 (可选) | 时间位置 |
返回
时间轴本身
可以与其他时间轴方法链式调用。
添加动画代码示例
import { createTimeline, animate } from 'animejs';
const circleAnimation = animate('.circle', {
x: '15rem'
});
const tl = createTimeline()
.sync(circleAnimation)
.add('.triangle', {
x: '15rem',
rotate: '1turn',
duration: 500,
alternate: true,
loop: 2,
})
.add('.square', {
x: '15rem',
});
<div class="large row">
<div class="medium pyramid">
<div class="triangle"></div>
<div class="square"></div>
<div class="circle"></div>
</div>
</div>