`offset` method returns incorrect value in Firefox #3080
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
offsetmethod returns incorrect value in Firefox.offsetmethod subtractsdocElem.clientTop/clientLeft(i.e.border-widthofhtmlelement), but Firefox seems to return0asclientTop/clientLeftofhtmlelement 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). Thebox1element in above code is positioned based onborder-boxeven ifhtmlhas border.And also,
htmlusually has no border.Then, I feel that
left: 0, top: 0is correct result, and it is useful.The text was updated successfully, but these errors were encountered: