Description
(Forking discussion from #211)
There are incompatibilities between Chrome, Edge, Firefox, and the spec on when exactly observer events should fire.
According to the spec:
Let thresholdIndex be the index of the first entry in observer.thresholds whose value is greater than intersectionRatio, or the length of observer.thresholds if intersectionRatio is greater than the last entry in observer.thresholds.
And
If thresholdIndex does not equal previousThresholdIndex, queue an IntersectionObserverEntry
So IntersectionObserverEntrys (events) should only be fired when the thresholdIndex
changes. However, what we've observed in our testing is that Chrome fires this event when isIntersecting
changes, regardless of whether thresholdIndex
changes (which we can observe through intersectionRatio
).
So for example, here is a test showing Chrome firing an extra event for an element whose intersectionRatio
does not change but whose isIntersecting
has changed. And here are the cross-browser results:
And here is a test showing Chrome not firing an event for an element whose isIntersecting
hasn't changed, but whose intersectionRatio
has changed. And here are the cross-browser results:
So roughly, here's the results with a ✔️ for event fired, and ❌ for event not being fired:
Spec | Chrome 59.0.3071.109 | Edge 15.15063 | Firefox Developer Edition 55.0b3 | |
---|---|---|---|---|
Demo 1 | ❌ | ✔️ | ❌ | ✔️ |
Demo 2 | ✔️ | ❌ | ✔️ | ✔️ |
Currently we (EdgeHTML) are weighing the options in our own implementation, but I'm interested to hear what Blink/Gecko folks think about this.