JSPM

  • Created
  • Published
  • Downloads 1180244
  • Score
    100M100P100Q198622F
  • License MIT

resize event emitter for elements.

Package Exports

  • element-resize-detector
  • element-resize-detector/src/browser-detector

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (element-resize-detector) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

element-resize-detector

Cross-browser resize event emitter for elements.

npm install element-resize-detector

Include script

Include the script in the browser:

<!DOCTYPE hml>
<html>
    <head></head>
    <body>
        <script src="node_modules/element-resize-detector/dist/element-resize-detector.min.js"></script>
    </body>
</html>

This will create a global function elementResieDetectorMaker, which is the maker function that makes an element resize detector instance.

You can also require it like so:

var elementResizeDetectorMaker = require("element-resize-detector");

Create instance

//With default options.
var erdDefault = elementResizeDetectorMaker();

API

listenTo(element, listener)

Listens to the element for resize events and calls the listener function with the element as argument on resize events.

Example usage:

erd.listenTo(document.getElementById("test"), function(element) {
  //Should probably use jQuery for the width and height for compability.
  var width = element.offsetWidth;
  var height = element.offsetHeight;
  console.log("Size: " + width + "x" + height);
});

Caveats:

  1. If the element has display: static it will be changed to display: relative. This means if you have unintentional top/right/bottom/left styles on the element (which was ignored when being static) they will now be applied to the element. This will also mean that if there are any elements with position: absolute as children to the element, they will now be positioned relative to the element.
  2. An <object> element will be injected as a direct child to the element. It has position: absolute so it will not affect the page flow. It is also visibly hidden.