I want the overlay timeline to start animating from the text2 label. That is, when the text-2 animation starts, the overlay timeline will start running.
gsap.registerPlugin(ScrollTrigger)
const tl = gsap.timeline({
scrollTrigger: {
trigger: '.section',
markers: true,
pin: true, // pin the trigger element while active
start: 'top top', // when the top of the trigger hits the top of the viewport
end: 'bottom top', // end after scrolling 500px beyond the start
scrub: true
}
})
tl.to('.text-1', { x: -400 });
tl.to('.text-2', { opacity: 1 }, "<");
tl.to('.text-2', { opacity: 0 }, "text2");
tl.to('.text-3', { opacity: 1 }, "<");
tl.to('.text-3', { opacity: 0 });
tl.to('.text-4', { opacity: 1 }, "<");
const tl2 = gsap.timeline({
scrollTrigger: {
trigger: '.section',
start: 'top top', // when the top of the trigger hits the top of the viewport
end: 'bottom top', // end after scrolling 500px beyond the start
scrub: true
}
})
tl2.to('.overlay', { opacity: 0.2 })
gsap.timeline()
.add(tl)
.add(tl2)