Thanks a lot @Yannis Yannakopoulos. Your answer really helps as it confirms my assumption. I have now found the events the theme dispatches before and after the transitions (it's not barba js but gsap they're using btw) and I'm listening for transitionOutStart (here I want to kill ScrollTrigger and transitionsDone (here I'll have to initialize ScrollTrigger if used on that page). But I don't really know on how to use ScrollTrigger.kill() as it's not orking as expected.
This is how I init ScrollTrigger:
gsap.registerPlugin(ScrollTrigger);
let tl = [];
let projects = ['omrfestival', 'mini', 'porsche', 'boa', 'dinnerberlin'];
for (i = 0; i < projects.length; i++) {
let tl = gsap.timeline({
scrollTrigger: {
trigger: ".portfolio--" + projects[i],
start: "top 70%",
end: "top 55%",
}
});
tl.addLabel("animateTitle")
.fromTo(".portfolio--"+projects[i]+" .portfolio__heading", {opacity: 0, x: -50}, {opacity: 1, x: 0, duration: 0.8})
.addLabel("animatePlane")
.fromTo(".portfolio--"+projects[i]+" .portfolio-img__plane", {opacity: 0, scaleX: 0, transformOrigin:'0% 0%', ease: "expo. out"}, {opacity: 1, scaleX: 1, duration: 0.5}, "-=0.3")
.addLabel("animateImage")
.fromTo(".portfolio--"+projects[i]+" .portfolio-img__image", {opacity: 0, x: -10}, {opacity: 1, x: 0, duration: 0.6}, "-=0.2")
.addLabel("animateDesc")
.fromTo(".portfolio--"+projects[i]+" .portfolio__desc", {opacity: 0, x: -10}, {opacity: 1, x: 0, duration: 0.6}, "-=0.2")
.addLabel("animateCTA")
.fromTo(".portfolio--"+projects[i]+" .portfolio__cta", {opacity: 0, x: -10}, {opacity: 1, x: 0, duration: 0.6}, "-=0.2");
}
And here's the eventListener
(function($) {
function exitPage() {
console.log("sempliceTransitionOutStart");
if (tl !== undefined) {
tl.kill();
console.log("kill ScrollTrigger");
}
}
function transitionsDone() {
console.log("sempliceTransitionsDone");
}
window.addEventListener("sempliceTransitionOutStart", exitPage );
window.addEventListener("sempliceTransitionsDone", transitionsDone );
})(jQuery);
In the console it show me that the kill section is beeing called but it doesn't destroy it as expected. I've tried both: tl.kill() and ScrollTrigger.kill(). None of them is working. What am I doing wrong?
Thanks so much for the help!
PS: I know that the code above can be optimized. I'm just strating to get into JS. I think utils.toArray() is what I'll have to look into next, right?