Skip to content

动效时间轴

有时候,我们希望能控制动效的播放顺序和时间。

me `Sunshine in the MIRROR`;
yohane.animate(p => {
p.x = 100;
p.duration = 2000;
});
yohane.instant(p => {
p.x = 0;
});
yohane.animate(p => {
p.x = 100;
p.duration = 2000;
});
yohane.animate(p => {
p.x = 0;
p.duration = 2000;
});

在默认情况下,所有动效将会依次播放:

  1. 第 0 ~ 2 秒中,移动到 x 为 100 的位置;
  2. 在前一个动画结束后,立即移动到 x 为 0 的位置;
  3. 第 2 ~ 4 秒中移动到 x 为 100 的位置;
  4. 第 4 ~ 6 秒中移动到 x 为 0 的位置。

timelabel 是只在单个语段中生效的标签,用于标记动效的时间锚点。

yohane.animate(p => {
p.x = 100;
p.duration = 2000;
});
timelabel("some-label");
yohane.animate(p => {
p.x = 100;
p.duration = 2000;
});
yohane.animate(p => {
p.y = 100;
p.duration = 2000;
p.timelabel = "some-label";
});

在这个情况下,动效的播放顺序如下:

  1. 第 0 ~ 2 秒中,移动到 x 为 100 的位置;
  2. 第 2 ~ 4 秒中移动到 x 为 100,y 为 100 的位置(两个动画同时播放)。

另一种方式是使用数字作为 timelabel 的值,这种方式会将 timelabel 转换为绝对时间戳(毫秒)。

yohane.animate(p => {
p.x = 100;
p.duration = 2000;
});
yohane.animate(p => {
p.x = 100;
p.duration = 2000;
});
yohane.animate(p => {
p.y = 100;
p.duration = 2000;
p.timelabel = 2000;
});
  1. 第 0 ~ 2 秒中,移动到 x 为 100 的位置;
  2. 第 2 ~ 4 秒中移动到 x 为 100,y 为 100 的位置(两个动画同时播放)。