Hi,
I have already used nextjs and GSAP together on other projects especially for a horizontal scroll for landing pages and it works without any problem
However, for a new project I need to use the scroll only on one section and that's where my problem starts.
I have read the documentation about the scrollTrigger and its properties, I have skimmed the GSAP forums as well as the different sandboxes and codepens but nothing to do, I'm stuck! The best result I could get is the one you see here and in the sandbox ....
https://codesandbox.io/p/github/Masta2000/Test-/draft/trusting-field?file=%2Fcomponents%2FHome%2FResults%2Findex.tsx&selection=[{"endColumn"%3A4%2C"endLineNumber"%3A19%2C"startColumn"%3A4%2C"startLineNumber"%3A19}]
useEffect(() => {
gsap.registerPlugin(ScrollTrigger);
ScrollTrigger.defaults({
markers: { startColor: "green", endColor: "red" },
});
let sections = gsap.utils.toArray(".item");
const container: HTMLElement = document.querySelector(".wrapper")!;
gsap.to(sections, {
xPercent: -100 * (sections.length - 1),
ease: "none",
scrollTrigger: {
pin: true,
pinnedContainer: container,
trigger: container,
scrub: 0.5,
end: () => "+=" + `${container.offsetWidth}`,
onEnter: () => console.log("in"),
onLeave: () => console.log("out"),
},
});
ScrollTrigger.refresh();
}, []);
I don't understand why my scroll doesn't stop at the end of my container as I think I told it to and also why it duplicates the element on which the scroll is applied twice ?
Besides, I don't really understand why either, I tested the pinnedContainer property which allows me to have the horizontal scroll because without it it doesn't work, for me it should because on my other works I didn't need to use this property at all but now it becomes indispensable and I would like to understand why in my case.
Here it is, I don't think that the problem comes from next or something else but we are never safe from a surprise and maybe someone more erudite than me on GSAP will be able to help me to see it more clearly ?
Thanks in advance and have a nice day ?