Bug Tracker

Opened 11 years ago

Closed 11 years ago

#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:
Blocked by: Blocking:

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 (5)

comment:1 Changed 11 years ago by jpsimons

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

comment:2 Changed 11 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 11 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;
            }
        }

comment:4 Changed 11 years ago by paul

Actually, it doesn't seem its that easy.. For me, it was the other way around - CSS1Compat mode had the 2px flaw, while BackCompat worked totally fine. Any idea?

comment:5 Changed 11 years ago by brandon

Resolution: fixed
Status: newclosed

Finally got a good fix for this in Rev 5942

Note: See TracTickets for help on using tickets.