jQuery.fn.offset = function( options ) {
var elem = this[0];
- if ( !elem || !elem.ownerDocument ) {
- return null;
- }
-
if ( options ) {
return this.each(function( i ) {
- jQuery.offset.setOffset( this, i, options );
+ jQuery.offset.setOffset( this, options, i );
});
}
+ if ( !elem || !elem.ownerDocument ) {
+ return null;
+ }
+
if ( elem === elem.ownerDocument.body ) {
return jQuery.offset.bodyOffset( elem );
}
- var box = elem.getBoundingClientRect(), doc = elem.ownerDocument, body = doc.body, docElem = doc.documentElement,
- clientTop = docElem.clientTop || body.clientTop || 0, clientLeft = docElem.clientLeft || body.clientLeft || 0,
- top = box.top + (self.pageYOffset || jQuery.support.boxModel && docElem.scrollTop || body.scrollTop ) - clientTop,
- left = box.left + (self.pageXOffset || jQuery.support.boxModel && docElem.scrollLeft || body.scrollLeft) - clientLeft;
+ var box = elem.getBoundingClientRect(),
+ doc = elem.ownerDocument,
+ body = doc.body,
+ docElem = doc.documentElement,
+ win = getWindow(doc),
+ clientTop = docElem.clientTop || body.clientTop || 0,
+ clientLeft = docElem.clientLeft || body.clientLeft || 0,
+ scrollTop = (win.pageYOffset || jQuery.support.boxModel && docElem.scrollTop || body.scrollTop ),
+ scrollLeft = (win.pageXOffset || jQuery.support.boxModel && docElem.scrollLeft || body.scrollLeft),
+ top = box.top + scrollTop - clientTop,
+ left = box.left + scrollLeft - clientLeft;
return { top: top, left: left };
};
jQuery.fn.offset = function( options ) {
var elem = this[0];
- if ( !elem || !elem.ownerDocument ) {
- return null;
- }
-
if ( options ) {
return this.each(function( i ) {
- jQuery.offset.setOffset( this, i, options );
+ jQuery.offset.setOffset( this, options, i );
});
}
+ if ( !elem || !elem.ownerDocument ) {
+ return null;
+ }
+
if ( elem === elem.ownerDocument.body ) {
return jQuery.offset.bodyOffset( elem );
}
left += parseFloat( computedStyle.borderLeftWidth ) || 0;
}
- prevOffsetParent = offsetParent, offsetParent = elem.offsetParent;
+ prevOffsetParent = offsetParent;
+ offsetParent = elem.offsetParent;
}
if ( jQuery.offset.subtractsBorderForOverflowNotVisible && computedStyle.overflow !== "visible" ) {
this.doesNotAddBorder = (checkDiv.offsetTop !== 5);
this.doesAddBorderForTableAndCells = (td.offsetTop === 5);
- checkDiv.style.position = "fixed", checkDiv.style.top = "20px";
+ checkDiv.style.position = "fixed";
+ checkDiv.style.top = "20px";
+
// safari subtracts parent border width here which is 5px
this.supportsFixedPosition = (checkDiv.offsetTop === 20 || checkDiv.offsetTop === 15);
checkDiv.style.position = checkDiv.style.top = "";
- innerDiv.style.overflow = "hidden", innerDiv.style.position = "relative";
+ innerDiv.style.overflow = "hidden";
+ innerDiv.style.position = "relative";
+
this.subtractsBorderForOverflowNotVisible = (checkDiv.offsetTop === -5);
this.doesNotIncludeMarginInBodyOffset = (body.offsetTop !== bodyMarginTop);
return { top: top, left: left };
},
- setOffset: function( elem, i, options ) {
+ setOffset: function( elem, options, i ) {
// set position first, in-case top/left are set even on static elem
if ( /static/.test( jQuery.curCSS( elem, "position" ) ) ) {
elem.style.position = "relative";