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
}
function add(l, t) {
- left += parseInt(l) || 0;
- top += parseInt(t) || 0;
+ left += parseInt(l, 10) || 0;
+ top += parseInt(t, 10) || 0;
}
return results;
// 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' );
},
offsetParent: function() {
- var offsetParent = this[0].offsetParent;
+ var offsetParent = this[0].offsetParent || document.body;
while ( offsetParent && (!/^body|html$/i.test(offsetParent.tagName) && jQuery.css(offsetParent, 'position') == 'static') )
offsetParent = offsetParent.offsetParent;
return jQuery(offsetParent);
// Create scrollLeft and scrollTop methods
jQuery.each( ['Left', 'Top'], function(i, name) {
- jQuery.fn[ 'scroll' + name ] = function(val) {
+ var method = 'scroll' + name;
+
+ jQuery.fn[ method ] = function(val) {
if (!this[0]) return;
return val != undefined ?
this.each(function() {
this == window || this == document ?
window.scrollTo(
- name == 'Left' ? val : jQuery(window)[ 'scrollLeft' ](),
- name == 'Top' ? val : jQuery(window)[ 'scrollTop' ]()
+ !i ? val : jQuery(window).scrollLeft(),
+ i ? val : jQuery(window).scrollTop()
) :
- this[ 'scroll' + name ] = val;
+ this[ method ] = val;
}) :
// Return the scroll offset
this[0] == window || this[0] == document ?
- self[ (name == 'Left' ? 'pageXOffset' : 'pageYOffset') ] ||
- jQuery.boxModel && document.documentElement[ 'scroll' + name ] ||
- document.body[ 'scroll' + name ] :
- this[0][ 'scroll' + name ];
+ self[ i ? 'pageYOffset' : 'pageXOffset' ] ||
+ jQuery.boxModel && document.documentElement[ method ] ||
+ document.body[ method ] :
+ this[0][ method ];
};
});