Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

.position() returns an offset from the static element on IE and Edge #4407

Open
YojiB opened this issue May 22, 2019 · 7 comments
Open

.position() returns an offset from the static element on IE and Edge #4407

YojiB opened this issue May 22, 2019 · 7 comments
Labels
Milestone

Comments

@YojiB
Copy link

YojiB commented May 22, 2019

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)

@mgol
Copy link
Member

mgol commented May 22, 2019

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.

@YojiB
Copy link
Author

YojiB commented May 23, 2019

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.

@dmethvin
Copy link
Member

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.

@YojiB
Copy link
Author

YojiB commented May 23, 2019

I knew #3479 but I thought it was different from this report.
However, this report is the same as #3887(and others).
thank you.

@timmywil
Copy link
Member

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 1d2df77.

@gibson042 I must be missing something.

@timmywil
Copy link
Member

timmywil commented Jul 1, 2019

This block will be replaced when we address #3479

@timmywil timmywil added this to the 4.0.0 milestone Jul 1, 2019
@mgol mgol added Offset and removed Dimensions labels Jul 1, 2019
@mgol
Copy link
Member

mgol commented Aug 21, 2019

Since #3479 has been scheduled for 3.4.2, I'll update the milestone here as well.

@mgol mgol modified the milestones: 4.0.0, 3.4.2 Aug 21, 2019
@mgol mgol modified the milestones: 3.5.0, 3.6.0 Mar 16, 2020
@Am294 Am294 mentioned this issue Apr 23, 2020
4 tasks
@mgol mgol modified the milestones: 3.6.0, 3.7.0 Jan 25, 2021
@mgol mgol modified the milestones: 3.6.1, 3.7.0 Mar 22, 2021
@timmywil timmywil modified the milestones: 3.7.0, 4.1.0 Feb 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

4 participants