Skip to content

Commit 85122fe

Browse files
FranckFreiburgermarcj
authored andcommitted
ResizeSensor.js optimization (marcj#172)
The aim of `getComputedStyle(element, 'position') == 'static'` is to detect that `element` is not "positioned". [`HTMLElement.offsetParent`](https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/offsetParent) returns the nearest positioned element in the containment hierarchy. `element.resizeSensor.offsetParent !== element` mean that `element` is not positioned. Right ?
1 parent a90832e commit 85122fe

File tree

1 file changed

+1
-17
lines changed

1 file changed

+1
-17
lines changed

src/ResizeSensor.js

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -92,22 +92,6 @@
9292
}
9393
}
9494

95-
/**
96-
* @param {HTMLElement} element
97-
* @param {String} prop
98-
* @returns {String|Number}
99-
*/
100-
function getComputedStyle(element, prop) {
101-
if (element.currentStyle) {
102-
return element.currentStyle[prop];
103-
}
104-
if (window.getComputedStyle) {
105-
return window.getComputedStyle(element, null).getPropertyValue(prop);
106-
}
107-
108-
return element.style[prop];
109-
}
110-
11195
/**
11296
*
11397
* @param {HTMLElement} element
@@ -138,7 +122,7 @@
138122
'</div>';
139123
element.appendChild(element.resizeSensor);
140124

141-
if (getComputedStyle(element, 'position') == 'static') {
125+
if (element.resizeSensor.offsetParent !== element) {
142126
element.style.position = 'relative';
143127
}
144128

0 commit comments

Comments
 (0)