ashthornton / asscroll

Ash's Smooth Scroll 🍑
MIT License
947 stars 27 forks source link

How to know when an element scrolls into view? #78

Closed ChaineYe closed 2 years ago

ChaineYe commented 2 years ago

Hii, thanx for this nice lib :) I wonder how to get one specific element's scroll position, or get a state like 'something-is-in-view-now' straightly. Is there anything I missed in the doc?

iamlinkus commented 2 years ago

Since ASScroll is a lightweight library (which is awesome, because it doesn't have the bloat other libs have), it doesn't include a solution which you are looking for "out of the box".

It is, however, very easy to achieve what you want with the use of intersectionObserver. You can read more about it here.

ChaineYe commented 2 years ago

@iamlinkus thanx for reply I checked other issues, in #37 , they said

'if that library relies solely on IntersectionObserver to detect when elements are in view, then unfortunately it won't be compatible with the smooth scroll technique that transforms the page, which is used by ASScroll and most other popular libraries.'

That makes me think whether intersectionObserver will do the job...
But again I appreciate your answer, I'll look into it later 👀👍🏻