Bug Tracker

Modify

Ticket #3345 (closed bug: fixed)

Opened 5 years ago

Last modified 5 years ago

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:1 Changed 5 years ago by jpsimons

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

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;
            }
        }

comment:4 Changed 5 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 5 years ago by brandon

  • Status changed from new to closed
  • Resolution set to fixed

Finally got a good fix for this in Rev 5942

Please follow the  bug reporting guidlines and use  jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

View

Add a comment

Modify Ticket

Action
as closed
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.