使用 ScrollMagic 为序列中的多个场景设置动画
Animating multiple scenes in a sequence with ScrollMagic
我正在尝试使用 ScrollMagic 和 GSAP 重建这个介绍效果:http://airnauts.com注意滚动时介绍 'slides'(带文本)如何一个接一个地显示和消失。
基本上,我已经设置了一个舞台控制器、一个场景(包含 div - '.hero-unit')和一些动画补间。但是,我就是不知道如何按这样的顺序为每张幻灯片(总共三张)制作动画:
- 您进入网站并开始滚动。
- 第一张幻灯片是动画的(使用 staggerFromTo 方法)。
- 当幻灯片完全动画后,将其不透明度降低回 0(或将其移出屏幕或其他)。
- 显示第二张幻灯片,如 2.
- 同3。
等等。
我尝试了在 Internet 上设法找到的所有解决方案。我尝试使用 'TimelineMax',尝试在使用 onComplete 完成动画后隐藏幻灯片,但似乎没有任何效果。这是我到目前为止的代码:
var pinOrigin = {
opacity: 0
};
var pinEnd = {
opacity: 1,
yoyo: true,
ease: Back.easeOut
}
var tl = TweenMax.staggerFromTo('.hero-unit .scene:first-of-type', 1, {opacity:0}, {opacity: 1});
var pin = new ScrollScene({
triggerElement: '.hero-unit',
triggerHook: 'onLeave',
duration: 1000
}).setPin('.hero-unit').setTween(tl).addTo(controller);
回顾一下:人们如何设法在不同的场景上演并在滚动时通过漂亮的过渡在它们之间切换?
好的,所以我自己弄明白了。您必须使用 TimelineMax(或者我猜是 Lite)并相对设置不同的场景移动,使用延迟作为 such:a
var tl = new TimelineMax().add([
TweenMax.to('.hero-unit .scene:first-of-type', 1, {opacity: 1}),
TweenMax.to('.hero-unit .scene:first-of-type', 1, {opacity: 0, delay: 1}),
TweenMax.to('.hero-unit .scene:nth-of-type(2)', 1, {opacity:1, delay: 2}),
TweenMax.to('.hero-unit .scene:nth-of-type(2)', 1, {opacity:0, delay: 3}),
TweenMax.to('.hero-unit .scene:nth-of-type(3)', 1, {opacity:1, delay: 4}),
TweenMax.to('.hero-unit .scene:nth-of-type(3)', 1, {opacity:0, delay: 5})
]);
var pin = new ScrollScene({
triggerElement: '.hero-unit',
triggerHook: 0,
duration: 2000
}).setPin('.hero-unit').setTween(tl).addTo(controller);
改进 我想补充一点,您可以将补间连续添加到时间轴中,它们将自动添加到时间轴的末尾。
因此,更好的动画代码方式是:
var tl = new TimelineMax()
.add(TweenMax.to('.hero-unit .scene:first-of-type', 1, {opacity: 1}))
.add(TweenMax.to('.hero-unit .scene:first-of-type', 1, {opacity: 0}))
.add(TweenMax.to('.hero-unit .scene:nth-of-type(2)', 1, {opacity:1}))
.add(TweenMax.to('.hero-unit .scene:nth-of-type(2)', 1, {opacity:0}))
.add(TweenMax.to('.hero-unit .scene:nth-of-type(3)', 1, {opacity:1}))
.add(TweenMax.to('.hero-unit .scene:nth-of-type(3)', 1, {opacity:0}));
这样代码更易于管理,以防您想随时添加任何内容。
有关详细信息,请查看 http://greensock.com/docs/#/HTML5/GSAP/TimelineMax/add/
如果您只想在时间线末尾添加一个.to 补间,您可以使用TimelineMax.to() method.
使其更加简洁
来自 GSAP 文档:
Adds a TweenLite.to() tween to the end of the timeline (or elsewhere using the "position" parameter) - this is a convenience method that accomplishes exactly the same thing as add( TweenLite.to(...) ) but with less code.
所以这将使它成为最适合您目的的 GSAP 动画代码:
var tl = new TimelineMax()
.to('.hero-unit .scene:first-of-type', 1, {opacity: 1})
.to('.hero-unit .scene:first-of-type', 1, {opacity: 0})
.to('.hero-unit .scene:nth-of-type(2)', 1, {opacity:1})
.to('.hero-unit .scene:nth-of-type(2)', 1, {opacity:0})
.to('.hero-unit .scene:nth-of-type(3)', 1, {opacity:1})
.to('.hero-unit .scene:nth-of-type(3)', 1, {opacity:0});
我正在尝试使用 ScrollMagic 和 GSAP 重建这个介绍效果:http://airnauts.com注意滚动时介绍 'slides'(带文本)如何一个接一个地显示和消失。
基本上,我已经设置了一个舞台控制器、一个场景(包含 div - '.hero-unit')和一些动画补间。但是,我就是不知道如何按这样的顺序为每张幻灯片(总共三张)制作动画:
- 您进入网站并开始滚动。
- 第一张幻灯片是动画的(使用 staggerFromTo 方法)。
- 当幻灯片完全动画后,将其不透明度降低回 0(或将其移出屏幕或其他)。
- 显示第二张幻灯片,如 2.
- 同3。 等等。
我尝试了在 Internet 上设法找到的所有解决方案。我尝试使用 'TimelineMax',尝试在使用 onComplete 完成动画后隐藏幻灯片,但似乎没有任何效果。这是我到目前为止的代码:
var pinOrigin = {
opacity: 0
};
var pinEnd = {
opacity: 1,
yoyo: true,
ease: Back.easeOut
}
var tl = TweenMax.staggerFromTo('.hero-unit .scene:first-of-type', 1, {opacity:0}, {opacity: 1});
var pin = new ScrollScene({
triggerElement: '.hero-unit',
triggerHook: 'onLeave',
duration: 1000
}).setPin('.hero-unit').setTween(tl).addTo(controller);
回顾一下:人们如何设法在不同的场景上演并在滚动时通过漂亮的过渡在它们之间切换?
好的,所以我自己弄明白了。您必须使用 TimelineMax(或者我猜是 Lite)并相对设置不同的场景移动,使用延迟作为 such:a
var tl = new TimelineMax().add([
TweenMax.to('.hero-unit .scene:first-of-type', 1, {opacity: 1}),
TweenMax.to('.hero-unit .scene:first-of-type', 1, {opacity: 0, delay: 1}),
TweenMax.to('.hero-unit .scene:nth-of-type(2)', 1, {opacity:1, delay: 2}),
TweenMax.to('.hero-unit .scene:nth-of-type(2)', 1, {opacity:0, delay: 3}),
TweenMax.to('.hero-unit .scene:nth-of-type(3)', 1, {opacity:1, delay: 4}),
TweenMax.to('.hero-unit .scene:nth-of-type(3)', 1, {opacity:0, delay: 5})
]);
var pin = new ScrollScene({
triggerElement: '.hero-unit',
triggerHook: 0,
duration: 2000
}).setPin('.hero-unit').setTween(tl).addTo(controller);
改进
因此,更好的动画代码方式是:
var tl = new TimelineMax()
.add(TweenMax.to('.hero-unit .scene:first-of-type', 1, {opacity: 1}))
.add(TweenMax.to('.hero-unit .scene:first-of-type', 1, {opacity: 0}))
.add(TweenMax.to('.hero-unit .scene:nth-of-type(2)', 1, {opacity:1}))
.add(TweenMax.to('.hero-unit .scene:nth-of-type(2)', 1, {opacity:0}))
.add(TweenMax.to('.hero-unit .scene:nth-of-type(3)', 1, {opacity:1}))
.add(TweenMax.to('.hero-unit .scene:nth-of-type(3)', 1, {opacity:0}));
这样代码更易于管理,以防您想随时添加任何内容。 有关详细信息,请查看 http://greensock.com/docs/#/HTML5/GSAP/TimelineMax/add/
如果您只想在时间线末尾添加一个.to 补间,您可以使用TimelineMax.to() method.
使其更加简洁
来自 GSAP 文档:
Adds a TweenLite.to() tween to the end of the timeline (or elsewhere using the "position" parameter) - this is a convenience method that accomplishes exactly the same thing as add( TweenLite.to(...) ) but with less code.
所以这将使它成为最适合您目的的 GSAP 动画代码:
var tl = new TimelineMax()
.to('.hero-unit .scene:first-of-type', 1, {opacity: 1})
.to('.hero-unit .scene:first-of-type', 1, {opacity: 0})
.to('.hero-unit .scene:nth-of-type(2)', 1, {opacity:1})
.to('.hero-unit .scene:nth-of-type(2)', 1, {opacity:0})
.to('.hero-unit .scene:nth-of-type(3)', 1, {opacity:1})
.to('.hero-unit .scene:nth-of-type(3)', 1, {opacity:0});