-
Notifications
You must be signed in to change notification settings - Fork 60
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
isIntersecting returns true when element is outside of viewport #24
Comments
I believe that's Chrome's issue, if you set the threshold only to 1. However Firefox behaves as you expect. If you modify to [0, 1] instead you should get the expected result in both. I'll have a closer look tomorrow, but looks like an issue with native behavior, so this must be documented in the polyfill repo by the relevant browser's team. |
Setting [0, 1] gives me the same behaviour as not setting threshold at all (Chrome 62.0.3202.94) . Shouldn't setting it to 1 give isIntersecting: true only when the whole element is in the viewport, and false when any part of it is outside the viewport? |
Indeed it should switch back to false after the threshold step. Here's the same codesandbox exhibiting the same behavior in Chrome with the native API: This proves that the behavior is native and has nothing to do with this repo. I think I have an idea of what's going on... If you scroll back up very aggressively you'll get the value to switch to |
According to this https://bugs.chromium.org/p/chromium/issues/detail?id=713819 it's expected behaviour so perhaps isIntersecting can't be used in this way. I guess checking intersectionRatio in combination with [0, 1] as targets would work but event.interSectionRatio in the callback doesn't give the exact value of the target intersectionRatio so only works in simple use cases (i.e checking less than or greater than). |
Feel free to close this btw as it's a native issue. |
Thanks for pasting the link, I wasn't fully aware of the purpose of |
Expected behavior
isIntersecting should return false when element is scrolled outside of viewport (with set threshold).
Current behavior
onChange triggers when element is scrolled out of viewport but returns true instead of false. This only seem to happen when threshold is set. When removing the threshold property everything works as expected.
Steps to reproduce
https://codesandbox.io/s/6z00y2vjwr
The text was updated successfully, but these errors were encountered: