-
Notifications
You must be signed in to change notification settings - Fork 20.6k
Offset: Increase search depth when finding the 'real' offset parent #4861
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
Conversation
Whoops, I thought I had fixed that failing test 😓😓 |
2ca829e
to
3dd9126
Compare
Finally tracked down the docs describing why the licence check was indeterminate - Fixed the erroneous author attributions for my commits |
Closing & re-opening the PR to trigger the EasyCLA check... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, this is good!
} | ||
if ( offsetParent && offsetParent !== elem && offsetParent.nodeType === 1 ) { | ||
if ( offsetParent && offsetParent !== elem && offsetParent.nodeType === 1 && | ||
jQuery.css( offsetParent, "position" ) !== "static" ) { | ||
|
||
// Incorporate borders into its offset, since they are outside its content origin | ||
parentOffset = jQuery( offsetParent ).offset(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While we're here making changes, we could also account for scrolling.
- // Incorporate borders into its offset, since they are outside its content origin
+ // The origin against which we will be returning a relative position is the absolute offset
+ // of offsetParent, plus the top/left width of its borders (since they are outside offsetParent's
+ // content origin), minus its top/left scroll position (which has already affected element
+ // absolute offset and should not be counted twice)
parentOffset = jQuery( offsetParent ).offset();
- parentOffset.top += jQuery.css( offsetParent, "borderTopWidth", true );
- parentOffset.left += jQuery.css( offsetParent, "borderLeftWidth", true );
+ parentOffset.top += jQuery.css( offsetParent, "borderTopWidth", true ) - offsetParent.scrollTop;
+ parentOffset.left += jQuery.css( offsetParent, "borderLeftWidth", true ) - offsetParent.scrollLeft;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess we should add some tests for this part of the behavior then as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Extracted to #5468. @gibson042 if you have nothing against, I'd merge this PR as-is and track the remaining changes via #5468. Let me know what you think.
Followup work extracted to #5468 per the last team meeting. |
Summary
Continue searching for the next positioned offsetParent (or the document) when calculating
position()
.This fixes the seemingly inconsistent behaviour that occurred when calling
position()
on elements inside tables; for which the offsetParent changes based on itsposition
css property. e.gPreviously
$('#static').position()
was returning the position relative to the containing<td>
element, while$('#relative').position()
was returning the position relative to#positioned-container
Now, both elements return their position relative to the containing
#positioned-container
Checklist