Bug in offset() for IE
Bug in offset() for IE
This probably Brandon's area ...
The inclusion of an HTML element with an id of 'box' causes IE to fail
in the offset method, reporting that "Object doesn't support this
property or method" and relating to elem.getBoundingClientRect(). This
is even though it has just passed a logic test for it!
The solution is to declare box locally, ie change
box = elem.getBoundingClientRect();
to
var box = elem.getBoundingClientRect();
The problem and solution can be seen demonstrated at
http://www.wizzud.com/tester/offset_quirks.html or
http://www.wizzud.com/tester/offset_standard.html (quirks mode or
standard mode respectively). Click 'fix #box bug' to run fixed code.
The demo is set up such that offset is called on the #box element
itself, but it will still fail if #box exists anywhere on the page and
offset() is called on any other element.
Ticket 1651 raised for the above.
As a side issue, the offset() method has some code to combat IE's 2px
html border offset, but in quirks mode it depends on the User having
removed the html border using css styling. If the default styling is
left in place then offset() returns incorrect values.
I have an alternative suggestion which can be seen in action on the
pages mentioned above (click 'apply mod' to switch in my code, and
'remove mod' to run original). The only time it should make any
difference is for IE in quirks mode.
The alternate code is
var dde = document.documentElement || {};
add(-(dde.clientLeft || 0), -(dde.clientTop || 0));
in place of
if ( msie ) {
var border = jQuery("html").css("borderWidth");
border = (border == "medium" || jQuery.boxModel && parseInt(version)