I have 3 blocks of text which appear as you scroll and I am fading in each one depending on where in the timeline the progress is.
I am wondering if there is any more efficient way to do this as the code below looks very redundant
tl.to(blocks,{
ease: 'power1.inOut',
duration: 100,
onUpdate: function () {
const progress = tl.progress();
if (progress > 0 && progress <= 0.5) {
gsap.killTweensOf([block2, block3]); // Cancel ongoing animations on block2 and block3
gsap.to(block1, { opacity: 1, y: 0, duration: opacityDuration });
gsap.set(block2, { opacity: 0, y: 15, });
gsap.set(block3, { opacity: 0, y: 15, });
} else if (progress > 0.5 && progress <= 0.7) {
gsap.killTweensOf([block1, block3]); // Cancel ongoing animations on block1 and block3
gsap.set(block1, { opacity: 0, y: 15, });
gsap.to(block2, { opacity: 1, y: 0, duration: opacityDuration });
gsap.set(block3, { opacity: 0, y: 15, });
} else if (progress > 0.7 && progress <= 1) {
gsap.killTweensOf([block1, block2]); // Cancel ongoing animations on block1 and block2
gsap.set(block1, { opacity: 0, y: 15, });
gsap.set(block2, { opacity: 0, y: 15 });
gsap.to(block3, { opacity: 1, y: 0, duration: opacityDuration });
}
}
}, '<');