X-Git-Url: http://git.asbjorn.it/?a=blobdiff_plain;f=src%2Foffset.js;h=f0adae04d9ceeffd51a2c43963c089e06d5001bf;hb=6141984b7115882cd84cb2cd2cae11de35914775;hp=a35fed5613e6c723a01be4231f47d416b3d0be33;hpb=831625c43e85a010064cac18b14ea49f1531c315;p=jquery.git diff --git a/src/offset.js b/src/offset.js index a35fed5..f0adae0 100644 --- a/src/offset.js +++ b/src/offset.js @@ -14,7 +14,7 @@ jQuery.fn.offset = function() { fixed = css(elem, "position") == "fixed"; // Use getBoundingClientRect if available - if ( elem.getBoundingClientRect ) { + if ( !(mozilla && elem == document.body) && elem.getBoundingClientRect ) { var box = elem.getBoundingClientRect(); // Add the document scroll offsets @@ -91,8 +91,8 @@ jQuery.fn.offset = function() { } function add(l, t) { - left += parseInt(l) || 0; - top += parseInt(t) || 0; + left += parseInt(l, 10) || 0; + top += parseInt(t, 10) || 0; } return results; @@ -107,11 +107,13 @@ jQuery.fn.extend({ // Get *real* offsetParent var offsetParent = this.offsetParent(), - // Get correct offsets - offset = this.offset(), - parentOffset = offsetParent.offset(); + // Get correct offsets + offset = this.offset(), + parentOffset = /^body|html$/i.test(offsetParent[0].tagName) ? { top: 0, left: 0 } : offsetParent.offset(); // Subtract element margins + // note: when an element has margin: auto the offsetLeft and marginLeft + // are the same in Safari causing offset.left to incorrectly be 0 offset.top -= num( this, 'marginTop' ); offset.left -= num( this, 'marginLeft' );