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() calculated incorrectly for elements inside a table #4431

Open
alons1 opened this issue Jul 14, 2019 · 11 comments
Open

Position() calculated incorrectly for elements inside a table #4431

alons1 opened this issue Jul 14, 2019 · 11 comments
Labels
Milestone

Comments

@alons1
Copy link

alons1 commented Jul 14, 2019

I've opened a bug in the past - #4149
It was closed and as far as I see, all linked issues to it are also closed.
So this should be fixed by now right?

Reproduces in Chrome / Firefox / Edge / IE11

https://jsfiddle.net/sectioni/pex37w8a/7/

@timmywil
Copy link
Member

timmywil commented Jul 22, 2019

Thanks. We need to double check the difference between the position offsetParent calculation and jQuery.fn.offsetParent. Specifically, the following doesn't seem to do anything useful, unless all it's supposed to do is get the document.

while ( offsetParent &&
  ( offsetParent === doc.body || offsetParent === doc.documentElement ) &&
  jQuery.css( offsetParent, "position" ) === "static" ) {
    offsetParent = offsetParent.parentNode;
}

@timmywil timmywil added this to the 3.4.2 milestone Jul 22, 2019
@mgol
Copy link
Member

mgol commented Jul 22, 2019

@gibson042 since this code was added by you in 1d2df77, do you know what it's supposed to do?

@tgfactor
Copy link

tgfactor commented Aug 9, 2019

Hello! I can concur that the position function is STILL broken, and it looks like it broke in version 3.3.0. I have a paragraph tag inside a table column that appears to the far right on my page. I just tested my application with 3.2.1 and the position is returning the correct top & left positions; when I switch to 3.3.0+ it returns left: 15, top: 13.

Please compare between those two versions to determine the location of the bug.

@timmywil
Copy link
Member

Ref #3479

@mgol mgol modified the milestones: 3.5.0, 3.6.0 Mar 16, 2020
@alons1
Copy link
Author

alons1 commented Aug 16, 2020

The security guy at our company asks me every month for the past 2 years to upgrade our jQuery 3.1.1 to the latest and every month I have to explain all over again that it will break our UI.

In order to maintain my sanity and avoid unnecessary rage outbreaks which will lead to me getting fired, can someone please fix this already?

Much appreciated.

@mgol
Copy link
Member

mgol commented Aug 16, 2020

@alons1 PRs welcome. If you care about something being fixed, you can speed it up by fixing that yourself & sending a PR.

@alons1
Copy link
Author

alons1 commented Aug 16, 2020

@mgol I'm unfamiliar with the project.
I could screw something else up since I don't know why this change was done in the first place.

@dmethvin
Copy link
Member

@alons1 The desire not to screw things up is why this ticket isn't moving. If the solution to this was obvious and we were certain we could do it without screwing something up, it would have been done long ago.

Someone needs to take the time to research the problem, look at any discussion when the change occurred and the tickets it was trying to fix, namely the ones mentioned in the 1d2df77 commit: gh-3080, gh-3107, gh-3096, gh-3487. Then someone needs to create a fix that works for all the supported browsers, including a test to prevent a regression. The second part is often easier than the research for the first!

@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
@jobeninc
Copy link

jobeninc commented Nov 18, 2021

Thanks. We need to double check the difference between the position offsetParent calculation and jQuery.fn.offsetParent. Specifically, the following doesn't seem to do anything useful, unless all it's supposed to do is get the document.

while ( offsetParent &&
  ( offsetParent === doc.body || offsetParent === doc.documentElement ) &&
  jQuery.css( offsetParent, "position" ) === "static" ) {
    offsetParent = offsetParent.parentNode;
}

I am pretty sure the && before the jQuery.css( offsetParent, "position" ) === "static" should be a ||

But, the entire logic should be re-evaulated. Sorry I don't have time to do a PR request but that change solved my immediate problem with trying to get an element position from inside a table tr td.

@jozefbriss
Copy link

It seems this PR might fix the problem #4861

@timmywil timmywil modified the milestones: 3.7.0, 4.1.0 Feb 13, 2023
@eli-collins
Copy link

Ran into this bug myself, position() was calculating offset from wrong parent. Can confirm the while() loop change in #4861 fixed my issue.

Alternately, my read on the loop was that the body & documentElement checks were supposed to stop the loop if offsetParent ever reached the root - adding just a "!" before that clause fixes things, though #4861's change is a bit more compact.

while ( offsetParent &&
  /* "!" added here ... */
  ! ( offsetParent === doc.body || offsetParent === doc.documentElement ) &&
  jQuery.css( offsetParent, "position" ) === "static" ) {
    offsetParent = offsetParent.parentNode;
}

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

8 participants