Hi all,
I'm trying to make a horizontal scroll with blocks of fluctuating sizes.
The content of my blocks can protrude when responsive, which is why I scroll horizontally then vertically, but since the blocks aren't one screen width wide I'm forced to cheat.
Depending on the height of each of my blocks, I increase the width of my container, then when I scroll over my blocks with the overhanging content, I trigger an upward animation and a margin on the left to simulate a vertical scroll.
My main problem is that my animations on blocks with protruding content are triggered at the start of my horizontal scroll and not when I arrive at my block.
When I activate my markers, they are not at the bottom of the screen as in these examples :
https://codepen.io/designcourse/pen/gOjZKOO
My code :
const container = document.querySelector(".__container");
const sections = gsap.utils.toArray(".__section");
const screenHeight = window.innerHeight;
let spaceTotal = 0;
sections.forEach(section => {
let drag = section.querySelectorAll(".__drag");
if(section.offsetHeight < screenHeight || drag.length === 0) return
let space = section.offsetHeight - screenHeight;
spaceTotal = spaceTotal + space;
gsap.to(drag,{
y: "-"+space,
marginLeft:space,
scrollTrigger: {
trigger: section,
containerAnimation: scrollTween,
start: 'left center',
scrub: 1,
markers: true,
}
});
});
function getScrollAmount() {
let containerWidth = container.scrollWidth + spaceTotal;
return -(containerWidth - window.innerWidth);
}
const scrollTween = gsap.to(sections, {
x: getScrollAmount,
duration: 3,
ease: "none",
});
ScrollTrigger.create({
trigger:".__container",
end: () => `+=${getScrollAmount() * -1}`,
pin:true,
animation:scrollTween,
scrub:1,
invalidateOnRefresh:true,
})
J'espère avoir été le plus clair possible.