Hi there, thanks for your help.
As you suggested I'm trying to understand how to calculate the scroll position for the horizontal section.
I created a new cpen: https://codepen.io/sml-k/pen/oNGNXRB
This is how I declare the horizontal scroll (whereas by drag or scroll):
//Scroll and drag
ScrollTrigger.matchMedia({
"(min-width: 1080px)": () => {
let scrollTween = gsap.to(sections, {
x: () =>
-(scrollContainer.scrollWidth - document.documentElement.clientWidth) + "px",
ease: "none",
scrollTrigger: {
trigger: scrollContainer,
invalidateOnRefresh: true, //check
pin: true,
scrub: 1,
end: () => "+=" + scrollContainer.offsetWidth,
},
});
var dragRatio =
scrollContainer.offsetWidth /
(window.innerWidth * (sections.length - 1));
var drag = Draggable.create(".proxy", {
trigger: scrollContainer,
type: "x",
onPress() {
this.startScroll = scrollTween.scrollTrigger.scroll();
},
onDrag() {
scrollTween.scrollTrigger.scroll(
this.startScroll - (this.x - this.startX) * dragRatio
);
},
})[0];
return () => {
scrollTween.kill();
drag.kill();
};
},
});
I think that the correct process would be define all the anchors, add an addEventListener and then run some function?
I didn't quite catch how to create and calculate the section's width and then run a scroll animation, could you help me? (for newby sake)