w3c / IntersectionObserver

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

Sub-pixel layout can cause intersectionRatio to be <1, even though target is entirely visible #477

Open szager-chromium opened 3 years ago

szager-chromium commented 3 years ago

First reported as a chromium bug:

https://bugs.chromium.org/p/chromium/issues/detail?id=1020466#c14

This is unexpected and useless behavior.

Off the top of my head: we could compute intersectionRatio based on pixel-snapped geometry. It would still be possible to derive intersectionRatio based on boundingClientRect and intersectionRect; but it would no longer be just a simple ratio of areas. It would also mean that in some cases (intersectionRatio == 1 && boundingClientRect != intersectionRect), which is also unintuitive.

comp615 commented 3 years ago

For what it's worth, it turns out this can also cause intersectionRatio >= 0 to be fired even before an item comes onscreen

SaidMarar commented 1 year ago

@szager-chromium This happen when display settings is big than 100%, so in my case i have 1.25 for window.devicePixelRatio

windows 10 display settings image