我在嘗試重新啓用scrollmagic控制器(如果它之前已被禁用)時遇到問題。在對象文字中禁用scrollmagic控制器es6
我想有標誌的顏色變化,如果它只是引發了窄視(如果該標誌是在彩色區)和殘疾人如果wide..that至今工作
,但如果我調整窗口的大小再次縮小它不會重新啓用controller..i試圖破壞和復位控制器以及但不知何故,它不會重新啓用控制器...
codepen(使用GSAP和scrollmagic): https://codepen.io/HendrikEng/pen/owyBYz?editors=0011
js:
const mobile = {
controller: new ScrollMagic.Controller(),
changeLogo: {
init:() => {
console.log("init tweens an scrollmagic");
const tweens = {
enterOuter:() => {
TweenMax.fromTo(
".c-logo__outer",
1,
{ fill: "#4dabfc" },
{ fill: "#fff" }
);
},
enterInner:() => {
TweenMax.fromTo(
".c-logo__inner",
1,
{ fill: "#fff" },
{ fill: "#4dabfc" }
);
},
leaveOuter:() => {
TweenMax.fromTo(
".c-logo__outer",
1,
{ fill: "#fff" },
{ fill: "#4dabfc" }
);
},
leaveInner:() => {
TweenMax.fromTo(
".c-logo__inner",
1,
{ fill: "#4dabfc" },
{ fill: "#fff" }
);
}
};
const trigger = document.querySelectorAll(".js-change-logo");
trigger.forEach(id => {
const scene = new ScrollMagic.Scene({
triggerElement: id,
reverse: true,
triggerHook: 0.065,
duration: id.clientHeight
})
.on("enter",() => {
tweens.enterOuter();
tweens.enterInner();
})
.on("leave",() => {
tweens.leaveOuter();
tweens.leaveInner();
})
.addIndicators()
.addTo(mobile.controller);
});
},
destroyTweens:() => {
console.log("kill tweens");
TweenMax.killTweensOf(".c-logo__outer");
TweenMax.killTweensOf(".c-logo__inner");
TweenMax.set(".c-logo__outer", { clearProps: "all" });
TweenMax.set(".c-logo__inner", { clearProps: "all" });
}
}
};
$(window).on("resize", function() {
var win = $(this); //this = window
if (win.width() <= 450) {
// reanble controller if disabledbed before - doesnt work
mobile.controller.enabled(true);
mobile.changeLogo.init();
} else {
// disable scrollmagic controller
mobile.controller.enabled(false);
// destroy tweens
mobile.changeLogo.destroyTweens();
}
}).resize();
非常感謝托馬斯,真正幫助和有意義。非常讚賞 – HendrikEng
例如如果我的移動設備有不同的動畫場景,最好是爲每個場景設置一個自己的scrollmagic控制器,或者爲所有的移動場景設置一個移動控制器。 – HendrikEng