Skip to content
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

Closed
klase opened this issue Dec 14, 2017 · 6 comments
Closed

isIntersecting returns true when element is outside of viewport #24

klase opened this issue Dec 14, 2017 · 6 comments
Labels

Comments

@klase
Copy link

klase commented Dec 14, 2017

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

@Rendez
Copy link
Contributor

Rendez commented Dec 14, 2017

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.

@klase
Copy link
Author

klase commented Dec 14, 2017

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?

@Rendez
Copy link
Contributor

Rendez commented Dec 15, 2017

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:
https://codesandbox.io/s/py9wmyy297

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 false sometimes, because of the async nature of this API. This indicates to me that Chrome treats intersections as inclusive, so it could be a case of edge-adjacent intersections. I guess we should open an issue in the w3c polyfill repo about this, in order to clarify the behavior.

@klase
Copy link
Author

klase commented Dec 15, 2017

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).

@klase
Copy link
Author

klase commented Dec 15, 2017

Feel free to close this btw as it's a native issue.

@Rendez
Copy link
Contributor

Rendez commented Dec 15, 2017

Thanks for pasting the link, I wasn't fully aware of the purpose of isIntersecting so I'll make sure to document the usages better. Cheers!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants