Hey, I'm having an issue whereby adding a ScrollTrigger with animations into a component is causing issues when navigating to different pages using the same component. The ScrollTrigger works fine when refreshing each page, but when you come from a previous page the trigger points are all way off as they haven't recalculated.
Interestingly, when navigating to a new page and then resizing the window, it seems to rebuild and loads the ScrollTrigger in correctly.
Does anybody know how to get this working correctly? I've tried previously suggested solutions such as killing the ScrollTrigger instance but nothing has yet worked successfully. My code in the component is below:
data() {
return {
animation: null,
st: null,
};
},
mounted() {
this.animation = gsap.timeline();
this.st = ScrollTrigger.create({
id: `featured-${ this.blok._uid }`,
trigger: `#featured-${ this.blok._uid }`,
markers: true,
start: 'top 75%',
end: 'bottom bottom',
pin: false,
scrub: 2,
animation: this.animation
});
this.st.refresh();
this.st.enable();
this.animation.from(
this.$refs.heading,
.8,
{
autoAlpha: 0,
y: 100,
}, '-=.6'
);
this.animation.from(
this.$refs.title,
.8,
{
autoAlpha: 0,
y: 100,
}, '-=.6'
);
this.animation.from(
this.$refs.content,
.8,
{
autoAlpha: 0,
y: 100,
}, '-=.6'
);
this.animation.from(
this.$refs.buttons,
.8,
{
autoAlpha: 0,
y: 100,
}, '-=.6'
);
this.animation.from(
this.$refs.additional,
.8,
{
autoAlpha: 0,
y: 100,
}, '-=.6'
);
},
beforeDestroy() {
this.st.kill();
},