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

Avoid counting scroll twice in offset #5468

Open
mgol opened this issue Apr 8, 2024 · 0 comments
Open

Avoid counting scroll twice in offset #5468

mgol opened this issue Apr 8, 2024 · 0 comments
Labels
Milestone

Comments

@mgol
Copy link
Member

mgol commented Apr 8, 2024

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;

Originally posted by @gibson042 in #4861 (comment)

@mgol mgol added the Offset label Apr 8, 2024
@mgol mgol added this to the 4.0.0 milestone Apr 8, 2024
@jquery jquery deleted a comment from Milobut May 15, 2024
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

1 participant