跳过主要内容

.getTween

.getTween( snap:Boolean ) : 补间动画

返回scrub默认补间动画(tween),或返回捕捉补间动画(getTween(true))

参数

  • snap:布尔值

    如果true如果正在进行 snap(吸附),则会返回当前的 snap tween,而不是 scrub tween。

返回值:Tween

scrub(拖拽)Tween 实例

细节

返回**scrub**tween(默认行为),它会使动画逐渐跟上滚动条位置。或者如果你调用了getTween(true),则会返回**snap**Tween(如果正在执行 snap 操作)。这允许你例如强制将其播放到结尾或销毁它,例如:scrub或者snap到其结尾或 kill(销毁)它,例如:

let st = ScrollTrigger.create({
animation: myTween,
scrub: 1,
trigger: ".panel-1",
});

// then later...
st.getTween().progress(1); // force the scrub to its end to make it catch up with the current scroll position immediately

或者中断一次 snap...

let anim = gsap.to(panels, {
x: () => (panels.length - 1) * window.innerWidth,
scrollTrigger: {
trigger: ".container",
snap: 1 / (panels.length - 1),
pin: true,
end: "+=3000",
},
});

// then later...
let snap = anim.scrollTrigger.getTween(true);
if (snap) {
snap.progress(1).kill(); // force the snap to its end and kill it
}

显然,只有在设置 ScrollTrigger 时定义了scrub或者snap值的情况下,这才有用。

无噪 Logo
无噪文档
中文文档 · 复刻官网
查看所有 ↗