There seems to be a logic error. It's working ok in the demo, however when I try and incorporate it into my react project, passing the first trigger causes the timeline to play once from beginning to end. I'm not really sure why it's happening. I'm now using xPercent for the tween which wasn't the case in the demo. I suspect it's something to do with the loop and the tweens creation? Here's the code from my react project.
mm.add("(min-width: 1300px)", () => {
tl.current = gsap.timeline({ paused: true });
for (let i = 0; i < btns.length; i++) {
if (i === 0) {
continue;
} else {
tl.current.to(".target", {
xPercent: "+=109.71",
duration: 1,
});
ScrollTrigger.create({
trigger: sections[i],
start: () => "top " + navHeight.current,
end: () => "bottom " + navHeight.current,
animation: tl.current,
onEnter: () => tl.current.tweenFromTo(i - 1, i),
onLeaveBack: () => tl.current.tweenFromTo(i, i - 1),
});
}
}
});