I've some problems with vue-router and gsap's scrolltrigger plugin. I have some vue components using scroltrigger and when I go to a different page and came back to the page having the scrolltrigger effect it doesn't trigger, but work if I manualy refresh the page.
I find this topic with people having the same problem with NuxtJs, but the ScrollTrigger.disable() and ScrollTrigger.kill() solutions not working for me : https://greensock.com/forums/topic/24886-in-nuxt-when-using-scrolltriggerkill-how-can-it-run-again-when-page-is-viewed/
Here is a component I made with ScrollTrigger :
Template Part
<template>
<section class="marquee">
<div class="marquee__inner" aria-hidden="true" ref="inner">
<div class="marquee__part">food wine fish beef vegetables</div>
<div class="marquee__part">food wine fish beef vegetables</div>
<div class="marquee__part">food wine fish beef vegetables</div>
<div class="marquee__part">food wine fish beef vegetables</div>
<div class="marquee__part">food wine fish beef vegetables</div>
</div>
</section>
</template>
Script part
<script>
import gsap from "gsap"
import ScrollTrigger from 'gsap/ScrollTrigger'
gsap.registerPlugin(ScrollTrigger)
export default {
name: 'ServicesMarquee',
data() {
return {
currentScroll: 0,
isScrollingDown: true,
test: null,
}
},
methods: {
scrollAnim() {
gsap.to(this.$refs.inner, {
xPercent: -65,
scrollTrigger: {
trigger: ".marquee",
start: "top bottom",
end: "top top",
scrub: 0,
}
})
},
},
mounted() {
gsap.set(this.$refs.inner, {xPercent: -50});
let tween = gsap.to(this.$refs.inner.querySelectorAll('.marquee__part'), {xPercent: -100, repeat: -1, duration: 10, ease: "linear"}).totalProgress(0.5);
let self = this
window.addEventListener("scroll", function(){
if ( window.pageYOffset > self.currentScroll ) {
self.isScrollingDown = true;
} else {
self.isScrollingDown = false;
}
gsap.to(tween, {
timeScale: self.isScrollingDown ? 1 : -1
});
self.currentScroll = window.pageYOffset
});
gsap.to(this.$refs.inner, {xPercent: -65 });
this.scrollAnim()
}
}
</script>