跳过主要内容

reverse

reverse(from:*, suppressEvents:Boolean):self

反向播放,使动画的所有方面都反向呈现,例如补间的缓动效果。

参数

  • 来自: *

    (默认值 =null) - 动画应该开始反向播放的时间点(或者时间轴实例的标签,如果没有定义,则将从当前播放头的位置开始反向播放)。若要从动画的最末尾开始播放,请使用0。负数表示相对于动画末尾的时间,例如-1表示距离末尾还有1秒。

  • suppressEvents:布尔值

    Boolean(默认值 =true) - 如果true(默认),当播放头移动到由from参数。

返回值:self

self(便于链式调用)

细节

反转播放,使动画所有部分都以相反方向进行,例如一个补间动画的缓动效果也会反转。这还将导致实例的timetotalTime倒退至零。您可以选择性地定义一个特定的时间点,在反转前跳转到该位置(默认情况下,它会从当前播放头位置开始反向播放)。调用reverse()还可确保实例既不暂停也不反转。

若要跳转到动画的最末尾并从那里开始反向播放,请将"from"参数设为0,如:reverse(0).

要检查实例是否已被反转,请使用reversed()方法,例如 if (myAnimation.reversed()) {...}

如果你定义了“from”时间(第一个参数,也可以是时间轴实例的标签),播放头会立即跳转到该位置,并且在播放头原来的位置和新时间点之间的任何事件/回调都不会被触发,因为默认情况下suppressEvents(第二个参数)为true。可以想象成像是将唱片机上的唱针提起并移动到新的位置,然后再放回唱片上。然而,如果你不希望在初始移动期间抑制这些事件/回调,请直接设置suppressEvents以获取一个false.

//reverses playback from wherever the playhead currently is:
tl.reverse();

//reverses playback from exactly 2 seconds into the animation:
tl.reverse(2);

//reverses playback from exactly 2 seconds into the animation but doesn't suppress events during the initial move:
tl.reverse(2, false);

//reverses playback from the very END of the animation:
tl.reverse(0);

//reverses playback starting from exactly 1 second before the end of the animation:
tl.reverse(-1);

//flips the orientation (if it's forward, it will go backward, if it is backward, it will go forward):
if (tl.reversed()) {
tl.play();
} else {
tl.reverse();
}

//flips the orientation using the reversed() method instead (shorter version of the code above):
tl.reversed(!tl.reversed());
无噪 Logo
无噪文档
中文文档 · 复刻官网
查看所有 ↗