简体   繁体   English

如何使用 Scroll Magic 插件延迟 GSAP 动画

[英]How to delay GSAP animation with Scroll Magic plugin

I'm trying to create simple kind of parallax animation on scroll and everything is working, but I want to add delay, for example user scrolling down and animation should catch him up, in another words, if he scrolled down 100px and stopped he should see how animation catching him up.我正在尝试在滚动上创建简单的视差动画并且一切正常,但我想添加延迟,例如用户向下滚动并且动画应该赶上他,换句话说,如果他向下滚动 100px 并停止他应该看看动画如何追上他。 so I have:所以我有:

<div class="container">
 <img src="...">
</div>

CSS: CSS:

.container {
 position: relative;
 height: 100vh;
 width: 100%;
 overflow: hidden;
}
img {
 position: absolute;
 top: 0;
 left: 0;
 width: 100%;
 height: 120%;
 object-fit: cover;
}

My JS:我的JS:

const controller = new ScrollMagic.Controller();

const titleParallaxScene = new ScrollMagic.Scene({
    triggerElement: '.container',
    triggerHook: 0,
    duration: '100%',
})
.setTween(TweenMax.to('.container img', 1, {y: '-20vh'}))
.addIndicators()
.addTo(controller);

I tried to add delay inside Tweenmax, but it only reduce duration and trigger hook.我试图在 Tweenmax 中添加延迟,但它只会减少持续时间和触发钩子。

Thanks in advance!提前致谢!

Just add an ease to your tween/timeline that ScrollMagic is using:只需为 ScrollMagic 使用的补间/时间线添加一个简单的内容:

.setTween(gsap.to('.container img', {duration: 1, y: '-20vh', ease: 'power3.in'}))

Note that this uses GSAP 3 formatting, but I think you're using it anyway given you are using vh units.请注意,这使用 GSAP 3 格式,但我认为您无论如何都在使用它,因为您使用的是 vh 单位。

You can add delay:# as an attribute to animation tweens.您可以添加 delay:# 作为补间动画的属性。 Also, you should remove the comma after duration.此外,您应该在持续时间后删除逗号。

const controller = new ScrollMagic.Controller();

const titleParallaxScene = new ScrollMagic.Scene({
    triggerElement: '.container',
    triggerHook: 0,
    duration: '100%' /* remove comma here */
})
.setTween(TweenMax.to('.container img', 1, {y: '-20vh', delay: 2})) /* add delay */
.addIndicators()
.addTo(controller);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM