4 ms·
While passive event listeners are an improvement, they are not a complete solution. It's more like the "least of evils". There is a new set of primitives that i
by Jonas_ba 9y ago
While passive event listeners are an improvement, they are not a complete solution. It's more like the "least of evils". There is a new set of primitives that is being implemented called IntersectionObserver which solves most of the issues of having to detect when something is in view + they run on a separate thread. So you don't need to do any computations, reading the window size and whatnot magic to detect if an element is inside the window. We are currently using this in prod for our algolia static websites and it has worked very well for the majority of all of our use cases.
https://github.com/WICG/IntersectionObserver/blob/gh-pages/explainer.md https://github.com/WICG/IntersectionObserver/blob/gh-pages/e...
- rjbwork 9y agoWhy do you need to detect whether something is in the viewport?
- eyelidlessness 9y agoThe linked description provides several use cases.
- SimeVidas 9y agoFor lazyloading stuff like images and ads. Or that technique where you have an infinite list, and the elements that are scrolled off-screen are recycled on the other end.
- esailija 9y agoYou can easily scroll so that the intersection observer sentinels are not seen and cause bugs. Disappointing.