Hello everyone,
I'm stuck on an issue that I can't resolve regarding using ScrollSmoother at the same time as ScrollTrigger.
In a web page, I have 3 JS files which take care of different things: main.js (basic file, common to many pages), header.js (takes care of the behavior of my header) and summary. js (which takes care of a component in the page). These 3 files are compiled by Webpack, so namespaces may change.
In main.js I instantiate ScrollSmoother
import gsap from 'gsap';
import { ScrollTrigger } from 'gsap/ScrollTrigger';
import { ScrollSmoother } from 'gsap/ScrollSmoother';
gsap.registerPlugin(ScrollTrigger, ScrollSmoother)
ScrollSmoother.create({
smooth: 1,
effects: true
})
In header.js I "pin" my header with ScrollTrigger and in summary.js I also "pin" a menu item.
import gsap from 'gsap';
import { ScrollTrigger } from 'gsap/ScrollTrigger';
import { ScrollSmoother } from 'gsap/ScrollSmoother';
gsap.registerPlugin(ScrollTrigger, ScrollSmoother)
ScrollTrigger.create({
trigger: this.container,
pin: this.summary,
start: 'top 15px',
end: `bottom ${this.summary.clientHeight + 15}px`,
markers: false
})
The problem is that without activating ScrollSmoother, the 2 pins work perfectly but as soon as I activate ScrollSmoother, the pins are no longer sticky.
The sticky behavior of the header and summary works again if I instantiate ScrollSmoother each time (so 3 times) but I feel that it is buggy because when scrolling it has "jumps".
Do you know how I can make ScrollTrigger instances work correctly with ScrollSmoother across different files?
Codesandbox demo : https://codesandbox.io/p/devbox/scrollsmoother-gt8pql
Thank you in advance
I tried to be as clear as possible in explaining my problem...
Matt