w3c / IntersectionObserver

Intersection Observer
https://www.w3.org/TR/intersection-observer/
Other
3.62k stars 531 forks source link

The ambiguity of intersectionRatio. #488

Open joekingTheThird3 opened 2 years ago

joekingTheThird3 commented 2 years ago

This is usually zero or larger. But the zero value is still valid and means at least 1 pixel is 'intersecting'. I've seen repeated code test just the intersectionRatio, 'intersectionRatio > 0'. This can cause some issues when scrolling because if it is zero then the test would miss the movement of the target element inside the root. I usually change the test to >= 0. I also test the isIntersecting property. I think people are using this shortcut for 'has this element moved inside the area I want to observe'. IntersectionRatio can never be less than zero? Maybe it should?

miketaylr commented 2 years ago

@joekingTheThird3 could you clarify what you're asking for or proposing here?