Skip to content

Commit 9644757

Browse files
committed
Offset: simplify jQuery#offsetParent method
* It seems, check for html element (and previously for body element) was redundant * Simplify "return" statement * Add comment about potential errors that didn't find themselves in real life app Ref 74ae544
1 parent 5d522f5 commit 9644757

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

src/offset.js

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,14 +149,24 @@ jQuery.fn.extend({
149149
};
150150
},
151151

152+
// This method will return documentElement in the following cases:
153+
// 1) For the element inside the iframe without offsetParent, this method will return
154+
// documentElement of the parent window
155+
// 2) For the hidden or detached element
156+
// 3) For body or html element, i.e. in case of the html node - it will return itself
157+
//
158+
// but those exceptions were never presented as a real life use-cases
159+
// and might be considered as more preferable results.
160+
//
161+
// This logic, however, is not guaranteed and can change at any point in the future
152162
offsetParent: function() {
153163
return this.map(function() {
154-
var offsetParent = this.offsetParent || docElem;
164+
var offsetParent = this.offsetParent;
155165

156-
while ( offsetParent && ( !jQuery.nodeName( offsetParent, "html" ) &&
157-
jQuery.css( offsetParent, "position" ) === "static" ) ) {
166+
while ( offsetParent && jQuery.css( offsetParent, "position" ) === "static" ) {
158167
offsetParent = offsetParent.offsetParent;
159168
}
169+
160170
return offsetParent || docElem;
161171
});
162172
}

0 commit comments

Comments
 (0)