Ticket #3345 (closed bug: fixed)
Offset function off by 2px in IE quirksmode
| Reported by: | jpsimons | Owned by: | brandon |
|---|---|---|---|
| Priority: | minor | Milestone: | 1.3 |
| Component: | offset | Version: | 1.2.6 |
| Keywords: | ie quirksmode quirks mode offset 2 pixels 2px | Cc: | |
| Blocking: | Blocked by: |
Description
This is well-explained in the jQuery comments:
IE adds the HTML element's border, by default it is medium which is 2px IE 6 and 7 quirks mode the border width is overwritable by the following css html { border: 0; } IE 7 standards mode, the border is always 2px This border/offset is typically represented by the clientLeft and clientTop properties However, in IE6 and 7 quirks mode the clientLeft and clientTop properties are not updated when overwriting it via CSS Therefore this method will be off by 2px in IE while in quirksmode
The fix is easy though, it's something like this:
if ($.browser.msie) {
var version = parseInt($.browser.version); if (version >= 6 && version <= 8 && document.compatMode == "BackCompat") {
offset.left -= 2; offset.top -= 2;
}
}
Since offset() is a mega-important function used for all kinds of popovers and things, it's worth adding a little code to make it reliably accurate.
Change History
comment:2 Changed 5 years ago by jpsimons
Let me try that again, using backticks:
` if ($.browser.msie) {
var version = parseInt($.browser.version); if (version >= 6 && version <= 8 && document.compatMode == "BackCompat") {
offset.left -= 2; offset.top -= 2;
}
} `
comment:3 Changed 5 years ago by jpsimons
Or braces:
if ($.browser.msie) {
var version = parseInt($.browser.version);
if (version >= 6 && version <= 8 && document.compatMode == "BackCompat") {
offset.left -= 2;
offset.top -= 2;
}
}
Please follow the bug reporting guidlines and use jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

Not sure what the heck the comment system did to my code, but you get the idea.