Observes size changes on a specific HTML element using ResizeObserver.
ResizeObserver
The target HTML element to observe.
Called with a ResizeObserverEntry when the element resizes.
ResizeObserverEntry
A cleanup function to disconnect the observer.
const box = document.querySelector('#box')!const stop = onElementResize(box, (entry) => { console.log('Element resized:', entry.contentRect)})// Later, to stop observing:stop() Copy
const box = document.querySelector('#box')!const stop = onElementResize(box, (entry) => { console.log('Element resized:', entry.contentRect)})// Later, to stop observing:stop()
Observes size changes on a specific HTML element using
ResizeObserver
.