DEV Community


Discussion on: How To Know If An Element Is Visible In Viewport.

andrewbridge profile image
Andrew Bridge

I've found getBoundingClientRect can become an expensive call if it's used a lot. The scroll event is fired very rapidly in some browsers too, so as with most things involving this event, it's usually worthwhile debouncing calls to your handler.

Of course if you're able to use the InteractionObserver as others have suggested then great! But your method provides a much wider browser compatibility!

emmaccen profile image
Lucius Emmanuel Emmaccen Author • Edited

Good feedback, Andrew.
By the looks of it, I should probably update the article. Everyone needs to know the cost of using getBoundingClientRect and how InteractionObserver might be a better fit in heavier projects.
By teaching, I've learnt a lot myself, thanks for pointing this out.