Simple Element Resize Detector Save

Observes element size changes using a hidden iframe

Project README

simple-element-resize-detector NPM

Observes resizing of an element using a hidden iframe.

JSFiddle Demo


npm i -S simple-element-resize-detector


import observeResize from 'simple-element-resize-detector';

// any DOM element that can have children
let element = document.createElement('div');

// listen for resize
observeResize(element, () => {
	console.log('new size: ', {
		width: element.clientWidth,
		height: element.clientHeight

To stop observing resize events, simply remove the returned detector frame:

let detector = observeResize(el, () => {});


// or, for better browser compatibility:
// detector.parentNode.removeChild(detector)


  • element passed to observeResize() must have position: relative style to be correctly observed, otherwise nearest relative ancestor will be observed instead.
  • This library uses <iframe>s to detect when an element resizes. <iframe>s are heavy objects are usually take good amount of memory. Be careful and don't abuse it.



Open Source Agenda is not affiliated with "Simple Element Resize Detector" Project. README Source: developit/simple-element-resize-detector

Open Source Agenda Badge

Open Source Agenda Rating