Hi there,
I'm trying to obtain a simple behaviour on my mobile version of the website:
The website will scroll naturally until I scroll down the horizontal section where the user shoud be able to scroll only 1 section at a time, I tried to use the normal horizontal scrolling functionality together with the snap configuration, however the snap is called only when the scroll ends so it will not result in fluid transition.
The result should be as the image below.
My only solution has been to use the pinned horizontal scrolltrigger together with an observer in order to scroll it section by section. Now the problem is that obviously the container is pinned for a fixed value, so if the user will scroll longer or shorter the end will be reached sooner or later, so I'd like to make something like a conditional end where it ends only when the last section has been reached.
I should also be able to scroll back and this will be another challenge.
Otherwise something to control the scroll power in order to set to a maximum of on section?
My website is deployed on this link https://m1947.micelio.studio/about-us/ , the horizontal section is displayed when clicking on "Expand" (3rd vertical section).
Here is my code at the moment:
const observer = Observer.create({
type: "wheel,touch,pointer",
wheelSpeed: -1,
onDown: () => {
if (!animatingHorizontal && currentIndex > 0) {
animatingHorizontal = true;
currentIndex--;
gsap.to(".timeline-year-container", {
x: -100 * currentIndex + "vw",
duration: scrollDuration / 2,
})
setTimeout(() => animatingHorizontal = false, 1000);
}
},
onUp: () => {
if (!animatingHorizontal) {
animatingHorizontal = true;
currentIndex++;
gsap.to(".timeline-year-container", {
x: -100 * currentIndex + "vw",
duration: scrollDuration / 2,
})
setTimeout(() => animatingHorizontal = false, 1000);
}
},
tolerance: 10,
preventDefault: true,
onEnable: () => allowScroll = false,
onDisable: (self) => allowScroll = true
});
observer.disable();
scrollTween = gsap.to(".timeline-year-container", {
// xPercent: "-700",
ease: "none",
scrollTrigger: {
trigger: "#slide-section-about-3",
pin: "#slide-section-about-3",
pinSpacing: true,
scrub: 0,
top: "top 0%",
end: () => `+=${$('.timeline-year-container').width()-window.innerWidth}`,
snap: {
snapTo: 1 / (sections.length - 1),
delay: 0,
duration: 0.3
},
onEnter: () => observer.enable(),
onEnterBack: () => observer.enable(),
onLeave: () => observer.disable(),
onLeaveBack: () => observer.disable(),
}
});