Showing with 48 additions and 298 deletions.
  1. +24 −15 src/offset.js
  2. +2 −0 test/data/offset/scroll.html
  3. +0 −272 test/data/ua.txt
  4. +21 −10 test/unit/offset.js
  5. +1 −1 test/unit/support.js
@@ -74,6 +74,7 @@ jQuery.offset = {

jQuery.fn.extend({
offset: function( options ) {
// Preserve chaining for setter
if ( arguments.length ) {
return options === undefined ?
this :
@@ -82,28 +83,36 @@ jQuery.fn.extend({
});
}

var docElem, win,
elem = this[ 0 ],
box = { top: 0, left: 0 },
doc = elem && elem.ownerDocument;
var docElem, win, rect, doc,
elem = this[ 0 ];

if ( !doc ) {
if ( !elem ) {
return;
}

docElem = doc.documentElement;
// Support: IE<=11+
// Running getBoundingClientRect on a
// disconnected node in IE throws an error
if ( !elem.getClientRects().length ) {
return { top: 0, left: 0 };
}

rect = elem.getBoundingClientRect();

// Make sure it's not a disconnected DOM node
if ( !jQuery.contains( docElem, elem ) ) {
return box;
// Make sure element is not hidden (display: none)
if ( rect.width || rect.height ) {
doc = elem.ownerDocument;
win = getWindow( doc );
docElem = doc.documentElement;

return {
top: rect.top + win.pageYOffset - docElem.clientTop,
left: rect.left + win.pageXOffset - docElem.clientLeft
};
}

box = elem.getBoundingClientRect();
win = getWindow( doc );
return {
top: box.top + win.pageYOffset - docElem.clientTop,
left: box.left + win.pageXOffset - docElem.clientLeft
};
// Return zeros for disconnected and hidden elements (gh-2310)
return rect;
},

position: function() {
@@ -11,6 +11,7 @@
#scroll-1-1 { top: 1px; left: 1px; }
#scroll-1-1-1 { top: 1px; left: 1px; }
#forceScroll { width: 5000px; height: 5000px; }
#hidden { display: none; }
#marker { position: absolute; border: 2px solid #000; width: 50px; height: 50px; background: #ccc; }
</style>
<script src="../../jquery.js"></script>
@@ -32,6 +33,7 @@
<div id="scroll-1-1-1" class="scroll"></div>
</div>
</div>
<div id="hidden"></div>
<div id="forceScroll"></div>
<div id="marker"></div>
<p class="instructions">Click the white box to move the marker to it.</p>