Hello, I am trying to make a consecutive animation on scroll that reverses the previous one and then executes the new one. Is this an optimal way, as I am trying to have different animations for each container? If not, can someone please show me a better one? Thanks a lot!
let tlForText = gsap.timeline();
let indexForText = 0;
const textAnimations = {
1: function() {
indexForText = 1;
tlForText .to('first-container', {
x: -100,
})
}
},
2: function() {
indexForText = 2;
tlForText .to('second-container', {
x: 100,
})
},
3: function() {
indexForText = 3;
tlForText .to('third-container', {
y: -100,
})
},
4: function(){
indexForText = 4;
tlForText .to('forth-container', {
x: -100,
})
}
5: function(){
indexForText = 5;
tlForText .to('first-container', {
x: 100,
})
},
}
const funcForText = (index) =>
{
index= indexForText;
if(index==! 0){
tlForText.reverse();
}
textAnimations[index]
};
ScrollTrigger.observe({
targer: window,
type: 'wheel, touch',
onUp: () => funcForText( indexForText - 1 ),
onDown: () => funcForText( indexForText + 1 ),
})