captivationsoftware / react-sticky

<Sticky /> component for awesome React apps
MIT License
2.64k stars 385 forks source link

Implement IntersectionObserver #219

Open malchata opened 7 years ago

malchata commented 7 years ago

Using code that binds scroll/resize events to check element visibility in the viewport are incredibly expensive, even if the code that is ran inside of them is throttled. This project should consider using IntersectionObserver to check for element visibility. It's a far more efficient and performant solution.

That said, not every browser out there supports IntersectionObserver, but writing logic that checks for it and falling back to traditional means is possible. There's also an IntersectionObserver polyfill as well.

vcarl commented 6 years ago

I agree with you, but as you note IntersectionObserver has poor browser support. Do you have any recommendations for only including the polyfill if the consumer doesn't already supply it? I'd like to avoid including redundant code if possible.