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!
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.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
I've found
getBoundingClientRectcan become an expensive call if it's used a lot. Thescrollevent 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
InteractionObserveras others have suggested then great! But your method provides a much wider browser compatibility!Good feedback, Andrew.
By the looks of it, I should probably update the article. Everyone needs to know the cost of using
getBoundingClientRectand howInteractionObservermight be a better fit in heavier projects.By teaching, I've learnt a lot myself, thanks for pointing this out.