mirror of
https://github.com/jquery/jquery.git
synced 2026-02-01 14:44:58 -05:00
Fix #10996, simplify offset code by forsaking ancient browsers.
This commit is contained in:
committed by
Dave Methvin
parent
91a6d9dafc
commit
77536f5cb2
@@ -1,11 +1,12 @@
|
||||
(function( jQuery ) {
|
||||
|
||||
var getOffset,
|
||||
rtable = /^t(?:able|d|h)$/i,
|
||||
rroot = /^(?:body|html)$/i;
|
||||
|
||||
if ( "getBoundingClientRect" in document.documentElement ) {
|
||||
getOffset = function( elem, doc, docElem, box ) {
|
||||
getOffset = function( elem, doc, docElem ) {
|
||||
var box;
|
||||
|
||||
try {
|
||||
box = elem.getBoundingClientRect();
|
||||
} catch(e) {}
|
||||
@@ -29,56 +30,12 @@ if ( "getBoundingClientRect" in document.documentElement ) {
|
||||
|
||||
} else {
|
||||
getOffset = function( elem, doc, docElem ) {
|
||||
var computedStyle,
|
||||
offsetParent = elem.offsetParent,
|
||||
prevOffsetParent = elem,
|
||||
body = doc.body,
|
||||
defaultView = doc.defaultView,
|
||||
prevComputedStyle = defaultView ? defaultView.getComputedStyle( elem, null ) : elem.currentStyle,
|
||||
top = elem.offsetTop,
|
||||
left = elem.offsetLeft;
|
||||
|
||||
while ( (elem = elem.parentNode) && elem !== body && elem !== docElem ) {
|
||||
if ( jQuery.support.fixedPosition && prevComputedStyle.position === "fixed" ) {
|
||||
break;
|
||||
}
|
||||
|
||||
computedStyle = defaultView ? defaultView.getComputedStyle(elem, null) : elem.currentStyle;
|
||||
top -= elem.scrollTop;
|
||||
left -= elem.scrollLeft;
|
||||
|
||||
if ( elem === offsetParent ) {
|
||||
top += elem.offsetTop;
|
||||
left += elem.offsetLeft;
|
||||
|
||||
if ( jQuery.support.doesNotAddBorder && !(jQuery.support.doesAddBorderForTableAndCells && rtable.test(elem.nodeName)) ) {
|
||||
top += parseFloat( computedStyle.borderTopWidth ) || 0;
|
||||
left += parseFloat( computedStyle.borderLeftWidth ) || 0;
|
||||
}
|
||||
|
||||
prevOffsetParent = offsetParent;
|
||||
offsetParent = elem.offsetParent;
|
||||
}
|
||||
|
||||
if ( jQuery.support.subtractsBorderForOverflowNotVisible && computedStyle.overflow !== "visible" ) {
|
||||
top += parseFloat( computedStyle.borderTopWidth ) || 0;
|
||||
left += parseFloat( computedStyle.borderLeftWidth ) || 0;
|
||||
}
|
||||
|
||||
prevComputedStyle = computedStyle;
|
||||
if ( !jQuery.contains( docElem, elem ) ) {
|
||||
return { top: 0, left: 0 };
|
||||
}
|
||||
var point = getWindow( doc ).webkitConvertPointFromNodeToPage( elem, new WebKitPoint( 0, 0 ) );
|
||||
return { top: point.y, left: point.x };
|
||||
|
||||
if ( prevComputedStyle.position === "relative" || prevComputedStyle.position === "static" ) {
|
||||
top += body.offsetTop;
|
||||
left += body.offsetLeft;
|
||||
}
|
||||
|
||||
if ( jQuery.support.fixedPosition && prevComputedStyle.position === "fixed" ) {
|
||||
top += Math.max( docElem.scrollTop, body.scrollTop );
|
||||
left += Math.max( docElem.scrollLeft, body.scrollLeft );
|
||||
}
|
||||
|
||||
return { top: top, left: left };
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user