我是 ScrollMagic 的新手,我正在努力解决问题。我正在一个具有相当复杂动画的网站上工作,但我还没有找到任何关于编写有效 ScrollMagic 代码的教程或示例。
我不是程序员,对 jQuery 和 JavaScript 有基本的了解。
此时我有以下代码(我知道它有点乱):
var controller;
$(document).ready(function($) {
// init controller
controller = new ScrollMagic({
globalSceneOptions: {
reverse: false
}
});
});
$(document).ready(function($) {
var tween = new TimelineMax()
.add( TweenMax.from(".helloHeadline", 1.5, {opacity: 0, ease: Sine.easeOut}), 0 )
.add( TweenMax.from(".helloTxt", 1.5, {opacity: 0, ease: Sine.easeOut}), 0 );
var scene = new ScrollScene({triggerElement: "#hello", duration: 0, offset: 0})
.setTween(tween)
.addTo(controller);
scene.addIndicators();
});
$(document).ready(function($) {
var tween = new TimelineMax()
.add( TweenMax.from(".components .simpleHeadline", 1.5, {opacity: 0, ease: Sine.easeOut}), 0 )
.add( TweenMax.from("#components_bg", 1.25, {scale: 0, ease: Elastic.easeOut}), .5 )
.add( TweenMax.from("#components_rabbit", 1.25, {scale: 0, ease: Elastic.easeOut}), 1 )
.add( TweenMax.from("#components_overlay", 1, {opacity: 0, ease: Sine.easeInOut}), 1.25 );
var scene = new ScrollScene({triggerElement: "#components_graphic", duration: 0, offset: -150})
.setTween(tween)
.addTo(controller);
scene.addIndicators();
});
$(document).ready(function($) {
var tween = TweenMax.from("#magic", 0.5,
{opacity: 0, ease: Quart.easeInOut}
);
var scene = new ScrollScene({triggerElement: "#magic", duration: 400, offset: 0, triggerHook: 1})
.setTween(tween)
.addTo(controller);
scene.addIndicators();
});
$(document).ready(function($) {
var tween = new TimelineMax()
.add( TweenMax.fromTo("#magic_hat", 0.01, {bottom: 800, opacity: 0}, {bottom: 800, opacity: 1}), 0 )
.add( TweenMax.to("#magic_hat", 1, {bottom: "0", ease: Bounce.easeOut}), 0.02 )
.add( TweenMax.from("#magic_hat_shadow", 1, {scale: 0, ease: Bounce.easeOut}), 0.02 )
.add( TweenMax.fromTo("#magic_hand", .75, {opacity: 0}, {opacity: 1, left: 60, top: -10 ,ease: Quart.easeIn}), .75 )
.add( TweenMax.to("#magic_hand", .5, {left: "-20", top: "4", ease: Circ.easeInOut, repeat: 2, yoyo: true}) )
.add( TweenMax.to("#magic_hand", .5, {left: "0", top: "0", ease: Quart.easeOut}) )
.add( TweenMax.from("#magic_hat_rabbit", .65, {top: "166", ease: Quart.easeOut}) );
var scene = new ScrollScene({triggerElement: "#magic", duration: 0, offset: 100})
.setTween(tween)
.addTo(controller);
scene.addIndicators();
});
$(document).ready(function($) {
var tween = TweenMax.from(".magicCntnt", 1,
{scale: 0, ease: Elastic.easeOut}
);
var scene = new ScrollScene({triggerElement: "#magic", duration: 0, offset: 200})
.setTween(tween)
.addTo(controller);
scene.addIndicators();
});
$(document).ready(function($) {
var tween = TweenMax.from("#works_macbook_top", 1,
{ rotationX: -80, ease: Sine.easeOut }
);
var scene = new ScrollScene({triggerElement: ".works .graphic", duration: 250, offset: -100, reverse: true})
.setTween(tween)
.addTo(controller);
scene.addIndicators();
});
var stuffDuration = 1;
$(document).ready(function($) {
var tween = TweenMax.from(".stuff.ruler", stuffDuration, {scale: 0, ease: Elastic.easeOut} );
var scene = new ScrollScene({triggerElement: ".stuff.ruler", duration: 0, offset: 0}).setTween(tween).addTo(controller);
});
$(document).ready(function($) {
var tween = TweenMax.from(".stuff.pencil", stuffDuration, {scale: 0, ease: Elastic.easeOut} );
var scene = new ScrollScene({triggerElement: ".stuff.pencil", duration: 0, offset: 0}).setTween(tween).addTo(controller);
});
$(document).ready(function($) {
var tween = TweenMax.from(".stuff.lightbulb", stuffDuration, {scale: 0, ease: Elastic.easeOut} );
var scene = new ScrollScene({triggerElement: ".stuff.lightbulb", duration: 0, offset: 0}).setTween(tween).addTo(controller);
});
我正在等待有关如何以更简单的方式管理此问题的提示。
我不确定是否需要单独的文档就绪函数,但我猜测声明相同的变量应该只在单独的函数中工作(抱歉,缺乏 JavaScript / jQuery 知识)。
有没有更短更有效的方法来管理多个场景和补间?欢迎任何提示!