w3c / IntersectionObserver

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

What is the meaning of isIntersecting? #328

Closed lsnch closed 6 years ago

lsnch commented 6 years ago

True if the target intersects with the root; false otherwise. This flag makes it possible to distinguish between an IntersectionObserverEntry signalling the transition from intersecting to not-intersecting; and an IntersectionObserverEntry signalling a transition from not-intersecting to intersecting with a zero-area intersection rect (as will happen with edge-adjacent intersections, or when the boundingClientRect has zero area).

Is it meant to distinguish in which direction the root is moving? Or is it just a shortcut for intersectionRatio !== 0?

This fiddle https://jsfiddle.net/wuka38z1/ shows different behaviors for Firefox and Chrome.

mpb commented 6 years ago

intersectionRatio !== 0 doesn't work super well with zero-area elements, so isIntersecting is meant to disambiguate that situation.

OZZlE commented 5 years ago

but can change.intersectionRatio ever be >0 if the element is in view but 0 height and 0 width?

ccjmne commented 5 years ago

@OZZlE Probably not.
However, consider the case where that zero-by-zero element is over an area of interest. Their intersectionRatio is 0, but (IIRC), isIntersecting would then be true.

OZZlE commented 5 years ago

@ccjmne thanks for clearing it up! :-)