Good day,
I am working on a project that uses GSAP in order to animate a Horizontal scroller that consists of a parent container and has 3 child divs. I am using GSAP to handle my horizontal scroller.
I would like to fix my code to allow snapping at the first div the user sees in the Horizontal Scroller. Then as the user continues to scroll it should snap to the second div and finally snap to the third div. As the user scrolls they should reach the last section div that will should not snap all snapping should happen only in the horizontal scroller.
My trouble: Getting the snap to happen when the user scrolls to the first div, and vice versa if the user scrolls back up it should snap to the third div.
Here is small diagram of what I am trying to achieve:
Small Layout of expected behavior
I have used code pen to reproduce a minimal example of my code.
In my code snapping is happening on each child div, however, snapping is not happening uppon entering container for div 1 and the same is not happening when the user scrolls back up when entering div 3.
I have tried: Changing my trigger point in gsap object, this lead to visual errors
gsap.to(videoSections, {
xPercent: -100 * (videoSections.length - 1),
ease: "none",
scrollTrigger: {
trigger: ".horizontal_container", // Here to trigger and initiate upon div 1
markers: true,
pin: true,
scrub: 0.5,
start: "top",
end: "+=3000",
snap: {
snapTo: [0, 0.5, 1],
duration: 0.05
}