UNPKG

element-height-observer

Version:

Allows you to add an efficient height listener to any dom element and execute a callback when its height changes

2 lines (1 loc) 1.06 kB
"use strict";function registerHeightObserver(e,t,r){var i,s;r?(i=t,s=r):(s=t,i={});var o=document.createElement("IFRAME");o.style.pointerEvents="none",o.style.position="absolute",o.style.display="block",o.style.overflow="auto",i&&"vertical"!==i.direction?("horizontal"===i.direction?o.style.height="0":o.style.height="100%",o.style.width="100%"):(o.style.height="100%",o.style.width="0"),o.style.top="0",o.style.bottom="0",o.style.left="0",o.style.border="0",o.style.backgroundColor="transparent",o.className="element-height-observer-iframe",o.onload=function(){o.contentWindow.addEventListener("resize",function(){s()})},e.appendChild(o),"static"!==e.style.position&&""!==e.style.position||(e.style.position="relative")}function unregisterHeightObserver(e){for(var t=e.children.length-1;0<=t;t--){var r=e.children.item(t);"element-height-observer-iframe"===r.getAttribute("class")&&r.remove()}}Object.defineProperty(exports,"__esModule",{value:!0}),exports.registerHeightObserver=registerHeightObserver,exports.unregisterHeightObserver=unregisterHeightObserver;