element-height-observer
Advanced tools
Comparing version 0.0.7 to 0.0.8
@@ -1,2 +0,5 @@ | ||
export declare function registerHeightObserver(element: HTMLElement, callback: () => void): void; | ||
export interface IHeightObserverOptions { | ||
direction?: 'both' | 'horizontal' | 'vertical'; | ||
} | ||
export declare function registerHeightObserver(element: HTMLElement, options: IHeightObserverOptions | (() => void), callback?: () => void): void; | ||
export declare function unregisterHeightObserver(element: HTMLElement): void; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
function registerHeightObserver(element, callback) { | ||
function registerHeightObserver(element, options, callback) { | ||
var opts; | ||
var cbk; | ||
if (!callback) { | ||
cbk = options; | ||
opts = {}; | ||
} | ||
else { | ||
opts = options; | ||
cbk = callback; | ||
} | ||
var iframe = document.createElement('IFRAME'); | ||
@@ -9,4 +19,14 @@ iframe.style.pointerEvents = 'none'; | ||
iframe.style.overflow = 'auto'; | ||
iframe.style.height = '100%'; | ||
iframe.style.width = '0'; | ||
if (!opts || opts.direction === 'vertical') { | ||
iframe.style.height = '100%'; | ||
iframe.style.width = '0'; | ||
} | ||
else if (opts.direction === 'horizontal') { | ||
iframe.style.height = '0'; | ||
iframe.style.width = '100%'; | ||
} | ||
else { | ||
iframe.style.height = '100%'; | ||
iframe.style.width = '100%'; | ||
} | ||
iframe.style.top = '0'; | ||
@@ -20,3 +40,3 @@ iframe.style.bottom = '0'; | ||
iframe.contentWindow.addEventListener('resize', function () { | ||
callback(); | ||
cbk(); | ||
}); | ||
@@ -23,0 +43,0 @@ }; |
@@ -1,1 +0,1 @@ | ||
"use strict";function registerHeightObserver(e,t){var r=document.createElement("IFRAME");r.style.pointerEvents="none",r.style.position="absolute",r.style.display="block",r.style.overflow="auto",r.style.height="100%",r.style.width="0",r.style.top="0",r.style.bottom="0",r.style.left="0",r.style.border="0",r.style.backgroundColor="transparent",r.className="element-height-observer-iframe",r.onload=function(){r.contentWindow.addEventListener("resize",function(){t()})},e.appendChild(r),"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; | ||
"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; |
{ | ||
"name": "element-height-observer", | ||
"version": "0.0.7", | ||
"version": "0.0.8", | ||
"description": "Allows you to add an efficient height listener to any dom element and execute a callback when its height changes", | ||
"main": "dist/index.min.js", | ||
"readme": "README.md", | ||
"types": "dist/index.d.ts", | ||
@@ -7,0 +8,0 @@ "scripts": { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
60026
66