Simple version of the code you wrote above. Here, goToPanel function is called with onEnter or onEnterBack and it creates a new tween every time the ScrollTrigger gets into the ".swipe-section".
function gotoPanel(index, isScrollingDown) {
...//
gsap.to(target, {
xPercent: isScrollingDown ? 0 : 100,
duration: 0.75,
onComplete: () => {
animating = false;
}
});
...//
}
ScrollTrigger.create({
trigger: ".swipe-section",
pin: true,
anticipatePin: true,
start: "top top",
end: "+=50%",
onEnter: (self) => {
intentObserver.enable();
gotoPanel(currentIndex + 1, true);
},
onEnterBack: (self) => {
intentObserver.enable();
gotoPanel(currentIndex - 1, false);
}
});