An event or observer for changes to getBoundingClientRect()

As mentioned in the comments above. The APIs you’re looking for are: ResizeObserver and IntersectionObserver. However, there are a few things to note: ResizeObserver will only fire when the observed element changes size. And it will essentially only give you correct values for width and height. Both ResizeObserver and IntersectionObserver are supposed to not block … Read more

JavaScript getBoundingClientRect() changes while scrolling

It is because getBoundingClientRect() gets values with respect to the window(only the current visible portion of the page), not the document(whole page). Hence, it also takes scrolling into account when calculating its values Basically, document = window + scroll So, to get the distance between myElement and the Y-coordinate=0 (top of document), you would have … Read more