darkroomengineering / lenis

How smooth scroll should be
https://lenis.darkroom.engineering
MIT License
9.13k stars 388 forks source link

Lenis seems to be messing with my Intersection Observer #386

Closed eduard-buta closed 1 month ago

eduard-buta commented 2 months ago

Describe the bug I've implemented a global Intersection Observer on my website that also has an unobserving functionality attached to it. Basically, since some elements enter the viewport when the user scrolls down, they're unobserved after they're animated. However, when Lenis is active on the same page, and a scroll up occurs after a scroll down, elements from my page that I haven't even reached with my initial scroll down are unobserved, suggesting that something is making my Intersection Observer go haywire.

Could this be due to the way Lenis works? Or is this something I could find a workaround for?

Update This bug also seems to trigger my animations down the page, not just messing with my intersection observer. I've tried rolling back to an earlier version of Lenis, and this behavior only happens with versions lenis@1.1.12 and lenis@1.1.13. Version lenis@1.1.11 works fine.

Somehow it seems that even if I scroll up, the scroll is perceived as a scroll down, triggering things like GSAP's ScrollTrigger or Intersection Observers. Now, this may be the way Lenis is supposed to work, it may be a bug caused by my code, or it may be an actual bug in Lenis.

I'll wait for an answer to figure out how to proceed. I hope the extra details helped pinpoint the potential problem.

clementroche commented 2 months ago

Can you share a codepen reproduction link please ?