Skip to main content

Bug Tracker

Side navigation

#3345 closed bug (fixed)

Opened September 09, 2008 04:11PM UTC

Closed November 13, 2008 02:48AM UTC

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.

Attachments (0)
Change History (5)

Changed September 09, 2008 04:13PM UTC by jpsimons comment:1

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

Changed September 09, 2008 04:47PM UTC by jpsimons comment:2

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;

}

}

`

Changed September 09, 2008 04:47PM UTC by jpsimons comment:3

Or braces:

        if ($.browser.msie) {
            var version = parseInt($.browser.version);
            if (version >= 6 && version <= 8 && document.compatMode == "BackCompat") {
                offset.left -= 2;
                offset.top -= 2;
            }
        }

Changed September 16, 2008 12:20PM UTC by paul comment:4

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?

Changed November 13, 2008 02:48AM UTC by brandon comment:5

resolution: → fixed
status: newclosed

Finally got a good fix for this in Rev 5942