.position() returns an offset from the static element on IE and Edge
The following code is an implementation of .position() from jquery-3.4.1.js.
// Account for the *real* offset parent, which can be the document or its root element
// when a statically positioned element is identified
doc = elem.ownerDocument;
offsetParent = elem.offsetParent || doc.documentElement;
while ( offsetParent &&
( offsetParent === doc.body || offsetParent === doc.documentElement ) &&
jQuery.css( offsetParent, "position" ) === "static" ) {
offsetParent = offsetParent.parentNode;
}
Does the .position() need the parent of root only ?
I do not think so.
If so, the code should be "if" and not "while".
( offsetParent === doc.body || offsetParent === doc.documentElement )
is not repeat condition, it is break condition I think.
In IE and Edge, if the target element in the table, the .position() returns offset from the table-cell (it's IE and Edge's offsetParent).
I guess the code is intended to be:
!( offsetParent === doc.body || offsetParent === doc.documentElement ) &&
Note by @mgol: I edited the post to add code formatting. (2019-07-01)
Thanks for the report. Can you provide a test case on JS Bin as the issue template requested? Thanks!
Also, please put code snippets in backticks: ```js for the beginning & ``` for the end; that makes code formatted properly.
test case: https://jsbin.com/gisomic/edit?html,css,js,output
Chrome(or FF, Safari) and Edge(or IE) have different results.
I'm sorry and I learned code formatting. I understand that fixing past posts is not a good way. If anyone requests it, I do it.
thank you.
I think it's all related to #3479, #3984, #3972, and #3887 but haven't looked to see if there are any unique issues here.
I knew #3479 but I thought it was different from this report. However, this report is the same as #3887(and others). thank you.
Hmm, when I look at the code, the while loop does look odd...
while ( offsetParent &&
( offsetParent === doc.body || offsetParent === doc.documentElement ) &&
jQuery.css( offsetParent, "position" ) === "static" ) {
offsetParent = offsetParent.parentNode;
}
I think the only thing that will be done here is set offsetParent to doc as long as body and html have position: static. I'm not sure that's what we want. This was changed in 1d2df772b4d6e5dbf91df6e75f4a1809f7879ab0.
@gibson042 I must be missing something.
This block will be replaced when we address https://github.com/jquery/jquery/issues/3479
Since #3479 has been scheduled for 3.4.2, I'll update the milestone here as well.