Есть такой код, я пытаюсь обернуть его в IF else чтобы была проверка, что указанные переменные существуют на странице.
var w = window.innerWidth;
var horizontalSlide = new TimelineMax();
var controller;
var size = w > 992 ? "big" : "small";
if (size === "big") {
makeScrollMagic();
}
function makeScrollMagic() {
controller = new ScrollMagic.Controller();
// animate panels
horizontalSlide.to("#js-slideContainer", 1, {x: "-20%"});
horizontalSlide.to("#js-slideContainer", 1, {x: "-40%"});
horizontalSlide.to("#js-slideContainer", 1, {x: "-60%"});
horizontalSlide.to("#js-slideContainer", 1, {x: "-90%"});
// create scene to pin and link animation
new ScrollMagic.Scene({
triggerElement: "#js-wrapper",
triggerHook: "onLeave",
duration: "1000%"
})
.setPin("#js-wrapper")
.setTween(horizontalSlide)
//.addIndicators() // add indicators (requires plugin)
.addTo(controller);
}
function sizeIt() {
w = window.innerWidth;
var newSize = w > 768 ? "big" : "small";
if (newSize != size) {
size = newSize;
if (newSize === "small") {
console.log("The screen is now small - ScrollMagic has been destroyed.");
TweenMax.set("#js-slideContainer", { clearProps: "all" });
horizontalSlide.clear();
controller.destroy(true);
} else {
console.log("The screen is now large - ScrollMagic is active.");
makeScrollMagic();
}
}
}
window.addEventListener("resize", sizeIt);