It is quite difficult for me to create a reproduction for this bug because it lives in a complex project. So I am asking for some possible directions/ideas that you can think of. Thanks!
The animation is to stagger several elements on Y position - sliding from bottom of page to their original positions.
Basically, the start position should be the top of the element's original position:
But ScrollTrigger marked the start position way down the page, causing the animation not triggered until scrolled very far:
I found this post, in which it was stated it's a bug:
Here is the code that sets up these (I'm using it in React):
const headerRef = useRef<HTMLElement>(null)
const q = gsap.utils.selector(headerRef)
useEffect(() => {
const animation = gsap.from(q('.stagger_elements'), {
y: '100vh',
stagger: 0.05,
ease: 'power4.out',
scrollTrigger: {
markers: true,
trigger: headerRef.current,
toggleActions: 'restart none none none',
},
})
return () => {
animation.kill()
}
}, [])
And to add more context, it typically works on DEV mode on my local machine. Once deployed, the trigger position is often wrong but sometimes after several refresh, it could get it right occasionally. - that's why I tried to create a demo but cannot reproduce it.
Could it be a bug? Any possible work arounds?
I need the start position to be the element's original top (where the red arrow line is).
Any ideas would be appreciated.