Gathering detailed insights and metrics for element-resize-detector
Gathering detailed insights and metrics for element-resize-detector
Gathering detailed insights and metrics for element-resize-detector
Gathering detailed insights and metrics for element-resize-detector
resize-detector
Element resize detection, both modern way and cross browser.
@types/element-resize-detector
TypeScript definitions for element-resize-detector
size-sensor
DOM element size sensor which will callback when size changed.
vue-element-resize-detector
vue directive for element-resize-detector
Optimized cross-browser resize listener for elements.
npm install element-resize-detector
Typescript
Module System
Node Version
NPM Version
99.1
Supply Chain
100
Quality
75.7
Maintenance
100
Vulnerability
100
License
JavaScript (99.3%)
HTML (0.7%)
Total Downloads
590,865,018
Last Day
61,688
Last Week
1,149,490
Last Month
5,006,600
Last Year
55,115,943
MIT License
1,318 Stars
332 Commits
115 Forks
20 Watchers
1 Branches
19 Contributors
Updated on May 16, 2025
Minified
Minified + Gzipped
Latest Version
1.2.4
Package Id
element-resize-detector@1.2.4
Unpacked Size
214.53 kB
Size
42.48 kB
File Count
28
NPM Version
6.14.8
Node Version
12.20.0
Published on
Dec 14, 2021
Cumulative downloads
Total Downloads
Last Day
-21.8%
61,688
Compared to previous day
Last Week
-11.6%
1,149,490
Compared to previous week
Last Month
10.9%
5,006,600
Compared to previous month
Last Year
-35.8%
55,115,943
Compared to previous year
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:
1<script src="node_modules/element-resize-detector/dist/element-resize-detector.min.js"></script>
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:
1var elementResizeDetectorMaker = require("element-resize-detector");
1// With default options (will use the object-based approach).
2var erd = elementResizeDetectorMaker();
3
4// With the ultra fast scroll-based approach.
5// This is the recommended strategy.
6var erdUltraFast = elementResizeDetectorMaker({
7 strategy: "scroll" //<- For ultra performance.
8});
There is also an callOnAdd
option, which determines if listeners should be called when they are getting added. Default is true. If true, the listener is guaranteed to be called when it has been added. If false, the listener will not be guarenteed to be called when it has been added (does not prevent it from being called).
Listens to the element for resize events and calls the listener function with the element as argument on resize events. Options passed to the function will override the instance options.
Example usage:
1erd.listenTo(document.getElementById("test"), function(element) { 2 var width = element.offsetWidth; 3 var height = element.offsetHeight; 4 console.log("Size: " + width + "x" + height); 5});
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.
If you need to listen to elements inside another document (such as an iframe), you need to init that document with this function. Otherwise the library won't be able to detect when elements are attached to the document. So for an iframe, simpy invoke erd.initDocument(iframe.contentDocument);
when the iframe is mounted on the DOM for the first time. The document from which the element resize detector instance is created will be initialized automatically. Notice that a new document is created when an iframe loads its content. So for iframes, be sure you invoke this function for each onLoad
iframe event.
position: static
it will be changed to position: relative
. Any unintentional top/right/bottom/left/z-index
styles 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.
A release that includes 1.1.15 and 1.1.16 with 1.2.0.
initDocument(document)
which is needed when listening to detached elements in other documents, such as iframes.important!
to most style properties, to avoid CSS overriding. Disabled by default.flex: none
. See #64.callOnAdd
being true. Also now removing onAnimationStart
listener when uninstalling. See #49.options.idHandler.get
.dir=RTL
.uninstall
supports being called with elements that haven't been initialized. uninstall
simply ignores non-erd elements.uninstall
now also supports a collection of elements.uninstall
may be called directly after a listenTo
call.window.getComputedStyle
instead 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.No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
Found 6/30 approved changesets -- score normalized to 2
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
88 existing vulnerabilities detected
Details
Score
Last Scanned on 2025-06-23
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More