Search

3/25/2008

Internet Explorer's handling of html element border widths is completely whack

John Resig - getBoundingClientRect is Awesome
/trunk/jquery/src/offset.js – jQuery – Development


15 // Use getBoundingClientRect if available
16 if ( elem.getBoundingClientRect ) {
17 var box = elem.getBoundingClientRect();
18
19 // Add the document scroll offsets
20 add(box.left + Math.max(doc.documentElement.scrollLeft, doc.body.scrollLeft),
21 box.top + Math.max(doc.documentElement.scrollTop, doc.body.scrollTop));
22
23 // IE adds the HTML element's border, by default it is medium which is 2px
24 // IE 6 and 7 quirks mode the border width is overwritable by the following css html { border: 0; }
25 // IE 7 standards mode, the border is always 2px
26 // This border/offset is typically represented by the clientLeft and clientTop properties
27 // However, in IE6 and 7 quirks mode the clientLeft and clientTop properties are not updated when overwriting it via CSS
28 // Therefore this method will be off by 2px in IE while in quirksmode
29 add( -doc.documentElement.clientLeft, -doc.documentElement.clientTop );

23 // IE adds the HTML element's border, by default it is medium which is 2px
24 // IE 6 and 7 quirks mode the border width is overwritable by the following css html { border: 0; }
25 // IE 7 standards mode, the border is always 2px
26 // This border/offset is typically represented by the clientLeft and clientTop properties
27 // However, in IE6 and 7 quirks mode the clientLeft and clientTop properties are not updated when overwriting it via CSS
28 // Therefore this method will be off by 2px in IE while in quirksmode
29 add( -doc.documentElement.clientLeft, -doc.documentElement.clientTop );

沒有留言: