Hi there! I am fairly new to GSAP, but already dug deep into the forums. That's where I found the helper function for horizontally looping a slider. Works like a charm.
Here I am using the helper function:
let sliderItems = document.querySelectorAll('.js-slider-item')
const images = gsap.utils.toArray(sliderItems)
const loop = horizontalLoop(images, {
repeat: -1,
paddingRight: '24px',
paused: true
})
Then, within the Observer, I am animating the progress of the horizontalLoop timeline like so:
const mapRange = gsap.utils.mapRange(0, window.innerWidth, 0, 1)
Observer.create({
target: '.js-wrapper',
type: 'pointer,touch,wheel',
wheelSpeed: -0.2,
onChange: (self) => {
const delta = Math.abs(self.deltaX) > Math.abs(self.deltaY) ? -self.deltaX : -self.deltaY
const scrub = gsap.to(loop, {
progress: loop.progress() + mapRange(delta) * 5,
duration: 1,
ease: 'power4.out'
})
scrub.invalidate().restart()
}
})
But here is my problem that I can't wrap my head around: When I first scroll to the left (positive direction on the timeline) and then backwards, the loop works as expected. But when my first drag or scroll is to the right (negative direction of the timeline – so the progress value would be negative), there is no movement at all. Until I scroll just a tiny bit to the left and then backwards....
I can't find any solution online, hoping that someone here is smarter than me.
Thanks so much!