Hey everyone, I am trying to recreate this codepen. But I have a horizontal scrolling website. So its kinda tricky... This is what I have so far
gsap.registerPlugin(ScrollTrigger);
gsap.registerPlugin(ScrollTrigger);
const scrollContainer = document.querySelector('.data-scroll-container');
const locoScroll = new LocomotiveScroll({
el: scrollContainer,
direction: 'horizontal',
smooth: true,
/*lerp: 0.1,*/
/*touchMultiplier: 2.54,*/
reloadOnContextChange: true,
tablet: {
smooth: true,
direction: 'horizontal',
gestureDirection: 'both',
},
smartphone: {
smooth: true,
direction: 'vertical',
}
});
window.onresize = function(){ location.reload(); }
locoScroll.on('scroll', ScrollTrigger.update);
ScrollTrigger.scrollerProxy(scrollContainer, {
scrollTop(value) {
return arguments.length ? locoScroll.scrollTo(value, 0, 0) : locoScroll.scroll.instance.scroll.y;
},
scrollLeft(value) {
return arguments.length ? locoScroll.scrollTo(value, 0, 0) : locoScroll.scroll.instance.scroll.x;
},
// we don't have to define a scrollLeft because we're only scrolling vertically.
getBoundingClientRect() {
return {top: 0, left: 0, width: window.innerWidth, height: window.innerHeight};
},
// LocomotiveScroll handles things completely differently on mobile devices - it doesn't even transform the container at all! So to get the correct behavior and avoid jitters, we should pin things with position: fixed on mobile. We sense it by checking to see if there's a transform applied to the container (the LocomotiveScroll-controlled element).
pinType: scrollContainer.style.transform ? "transform" : "fixed"
});
window.addEventListener("load", function () {
let pinBoxes = document.querySelectorAll(".pin-wrap > *");
let pinWrap = document.querySelector(".pin-wrap");
let pinWrapWidth = pinWrap.offsetHeight ;
let horizontalScrollLength = pinWrapWidth - window.innerHeight;
gsap.to(".pin-wrap", {
scrollTrigger: {
scroller: scrollContainer, //locomotive-scroll
scrub: true,
trigger: "#sectionPin",
onEnter:() => {
console.log("Enter")
},
pin: true,
//horizontal: true,
// anticipatePin: 1,
start: "left center",
end: pinWrapWidth
},
/*y: -horizontalScrollLength,
ease: "none"*/
});
// each time the window updates, we should refresh ScrollTrigger and then update LocomotiveScroll.
ScrollTrigger.addEventListener("refresh", () => locoScroll.update());
// after everything is set up, refresh() ScrollTrigger and update LocomotiveScroll because padding may have been added for pinning, etc.
ScrollTrigger.refresh();
});
I cant seem to find out why its not working. The structure of my DOM is similiar as in the codepen. Special is that I use Elementor as my base, but it should not have any affect on this.
As attribute I do have data-section in each section, as its not working else...
Hope someone can help me!!! ❤️
Cheers
zoruak