In my react application I am using two scroll triggers, one for the main "reveal" animation and another for "another" animation. The problem is that when the scrollTrigger markers are set for the "another" animation the "reveal" animation hasn't happened yet and that causes an offset in the "another" animation markers. Here is what I am talking about:
The start and end markers should be where the red line is, but instead they are offset by 70px. This is because when the page loads the "reveal" animation that moves the whole element up 70px hasn't ran and it only runs when the element has come into view. Here is the code:
The reveal animation that is offseting the element(translateY):
useLayoutEffect(() => {
if (elementToAnimate) {
const context = gsap.context(() => {
gsap.from(elementToAnimate, {
duration: 0.55,
translateY: 70,
opacity: 0,
ease: 'power.out',
scrollTrigger: {
trigger: elementToAnimate,
toggleActions: toogleActions
? toogleActions
: 'restart reverse restart reverse',
start: 'top 90%',
end: 'bottom 10%',
},
});
});
return () => context.revert();
}
}, [elementToAnimate]);
The "another" animation(the important part of the code below is that it sets it's markers by the horizontalBorderToAnimate which is initialy offset by 70px since the "reveal" animation hasn't ran yet):
useLayoutEffect(() => {
const horizontalBorderToAnimate = horizontalBorderBottomRef.current;
const verticalBorderToAnimate = verticalBorderRightRef.current;
if (horizontalBorderToAnimate && verticalBorderToAnimate) {
const customToggleActions = 'restart reverse restart reverse';
const context = gsap.context(() => {
gsap.from(horizontalBorderToAnimate, {
duration: 0.55,
ease: 'power.out',
width: '100%',
scrollTrigger: {
markers: true,
trigger: horizontalBorderToAnimate,
toggleActions: customToggleActions,
},
});
gsap.from(verticalBorderToAnimate, {
duration: 0.55,
ease: 'power.out',
height: '100%',
scrollTrigger: {
trigger: horizontalBorderToAnimate,
toggleActions: customToggleActions,
},
});
});
return () => context.revert();
}
}, []);
How should I fix this?