Hi, i don't know if this belongs here but i have a strange behaviour on my site. I made a horizontal scroll website with ScrollTrigger. The (sub)pages have different lengths/widths but everything uses the same JS. If I scroll once with the mouse, you jump different distances depending on the length of the page. I really don't know how to fix this. Is there any parameter i could use to handle this?
I don't have a Codepen link due the fact u cant have 2 different pages. I can post the link to my testserver with the actual page if this is allowed.
But this is my ScrollTrigger code:
ScrollTrigger.matchMedia({
"(min-width: 992px)": function () {
ScrollTrigger.normalizeScroll(true);
}
});
const getMaxWidth = () => {
maxWidth = 0;
sections.forEach((section) => {
maxWidth += section.offsetWidth;
});
};
const setupScrollTrigger = () => {
ScrollTrigger.matchMedia({
"(min-width: 992px)": function () {
sections = gsap.utils.toArray("section");
getMaxWidth();
ScrollTrigger.addEventListener("refreshInit", getMaxWidth);
scrollTween = gsap.to(sections, {
x: () => `-${maxWidth - window.innerWidth}`,
ease: "none",
scrollTrigger: {
trigger: ".wrapper",
pin: true,
scrub: 0.5,
end: () => `+=${maxWidth/3}`,
invalidateOnRefresh: true
}
});
}
});
}
Thanks in advance
Gui