

It's important to note that while ResizeObserver reports both the dimensions of the contentRect and the padding, it only watches the contentRect. The content box is the box in which content can be placed. Generally, a ResizeObserverEntry reports the content box of an element through a property called contentRect, which returns a DOMRectReadOnly object. observe (someElement ) Some details # What is being reported? # var ro = new ResizeObserver ( entries => px ` ) The callback is passed an array of ResizeObserverEntry objects-one entry per observed element-which contains the new dimensions for the element. You create a ResizeObserver object and pass a callback to the constructor.

This didn't even cover cases where elements change their size without the main window having been resized.

If you needed the new dimensions of an element after a resize, you had to call getBoundingClientRect() or getComputedStyle(), which can cause layout thrashing if you don't take care of batching all your reads and all your writes. In the event handler, you would then have to figure out which elements have been affected by that change and call a specific routine to react appropriately. Before ResizeObserver, you had to attach a listener to the document's resize event to get notified of any change of the viewport's dimensions.
