Optimized cross-browser resize listener for elements. Up to 37x faster than related approaches (read section 5 of the article).
npm install element-resize-detector
Include the script in the browser:
This will create a global function
elementResizeDetectorMaker, which is the maker function that makes an element resize detector instance.
You can also
require it like so:
var elementResizeDetectorMaker = ;
// With default options (will use the object-based approach).// The object-based approach is deprecated, and will be removed in v2.var erd = ;// With the ultra fast scroll-based approach.// This will be the default in v2.var erdUltraFast =;
Listens to the element for resize events and calls the listener function with the element as argument on resize events.
Removes the listener from the element.
Removes all listeners from the element, but does not completely remove the detector. Use this function if you may add listeners later and don't want the detector to have to initialize again.
Completely removes the detector and all listeners.
position: staticit will be changed to
position: relative. Any unintentional
top/right/bottom/left/z-indexstyles will therefore be applied and absolute positioned children will be positioned relative to the element.
Big thanks to Evry sponsoring this project.
This library is using the two approaches (scroll and object) as first described at http://www.backalleycoder.com/2013/03/18/cross-browser-event-based-element-resize-detection/.
The scroll based approach implementation was based on Marc J's implementation https://github.com/marcj/css-element-queries/blob/master/src/ResizeSensor.js.
Please note that both approaches have been heavily reworked for better performance and robustness.
flex: none. See #64.
callOnAddbeing true. Also now removing
onAnimationStartlistener when uninstalling. See #49.
uninstallsupports being called with elements that haven't been initialized.
uninstallsimply ignores non-erd elements.
uninstallnow also supports a collection of elements.
uninstallmay be called directly after a
window.getComputedStyleinstead of relying on the method being available in the global scope. This enables this library to be used in simulated browser environments such as jsdom.