-
Notifications
You must be signed in to change notification settings - Fork 20.6k
offset
method returns incorrect value in Firefox
#3080
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
Comments
The jQuery code predates the existence of
I suspect that is why this hasn't been reported or noticed, if it is actually a bug.
If the HTML element has a border would the position be from the inside of the border, or the outside? I don't know and a quick search into the specs didn't help. Now we need some people who actually understand how we got here. Maybe @mikesherov ? |
Very odd. If anything it should add margins in I have just filed a Firefox bug for the clientLeft/clientTop issue. |
|
I see. <html>
<body>
<div id="box1"></div>
<div id="box2"></div>
</body>
</html> html {
border: 10px solid red;
}
body {
border: 10px solid blue;
margin: 20px;
padding: 30px;
}
#box1, #box2 {
position: absolute;
width: 50px;
height: 50px;
}
#box1 {
background-color: rgba(0, 128, 0, 0.5); /* translucent green */
left: 0;
top: 0;
}
#box2 {
background-color: rgba(128, 0, 0, 0.5); /* translucent red */
} $('#box2').offset($('#box1').offset()); I gave a Result in Firefox seems correct. The setter of |
Line 435 in 9f268ca
If native event don't have pageX/Y , these are calculated using clientLeft/clientTop .
If I feel that But I don't know recent browser that doesn't support |
Let's keep this issue focused on |
@gibson042 Ok, I will make a new issue about Yes, I can write PR. I already removed the code that subtract |
I just did some further exploration, and confirmed that all four engines respect document element margin as well (and do so independently of absolute positioning). So, to revise the above, |
|
The new tests will be limited to |
Thank you for your care 😃 I will send PR later. |
Related to: jquery#3080 Remove unnecessary code that subtracts `document.documentElement.clientTop/clientLeft` (i.e. `border-width` of `<html>`) from coordinates. In Firefox, those are not subtracted because `clientTop/clientLeft` are `0` always by accidentally bug.
Related to: jquery#3080 Remove unnecessary code that subtracts `document.documentElement.clientTop/clientLeft` (i.e. `border-width` of `<html>`) from coordinates. In Firefox, those are not subtracted because `clientTop/clientLeft` are `0` always by accidentally bug.
Thank you 😄 |
Hi,
I found a case that
offset
method returns incorrect value in Firefox.offset
method subtractsdocElem.clientTop/clientLeft
(i.e.border-width
ofhtml
element), but Firefox seems to return0
asclientTop/clientLeft
ofhtml
element always.For example:
https://jsfiddle.net/xwuc0g6q/
Res in Google Chrome:
Res in IE:
Res in Firefox:
But I can't understand why the method subtracts
docElem.clientTop/clientLeft
.If it do that for getting the position relative to the document, it should calculate based on
border-box
(i.e. outline that includes border). Thebox1
element in above code is positioned based onborder-box
even ifhtml
has border.And also,
html
usually has no border.Then, I feel that
left: 0, top: 0
is correct result, and it is useful.The text was updated successfully, but these errors were encountered: