mirror of
https://github.com/jquery/jquery.git
synced 2026-02-01 11:04:56 -05:00
CSS: Protect against getBoundingClientRect exceptions
Ref487d5ca913Ref6df399073c
This commit is contained in:
21
src/css.js
21
src/css.js
@@ -437,12 +437,21 @@ jQuery.cssHooks.marginRight = addGetHookIf( support.reliableMarginRight,
|
||||
jQuery.cssHooks.marginLeft = addGetHookIf( support.reliableMarginLeft,
|
||||
function( elem, computed ) {
|
||||
if ( computed ) {
|
||||
return ( parseFloat( curCSS( elem, "marginLeft" ) ) ||
|
||||
elem.getBoundingClientRect().left -
|
||||
swap( elem, { marginLeft: 0 }, function() {
|
||||
return elem.getBoundingClientRect().left;
|
||||
} )
|
||||
) + "px";
|
||||
return (
|
||||
parseFloat( curCSS( elem, "marginLeft" ) ) ||
|
||||
|
||||
// Support: IE<=11+
|
||||
// Running getBoundingClientRect on a disconnected node in IE throws an error
|
||||
// Support: IE8 only
|
||||
// getClientRects() errors on disconnected elems
|
||||
( jQuery.contains( elem.ownerDocument, elem ) ?
|
||||
elem.getBoundingClientRect().left -
|
||||
swap( elem, { marginLeft: 0 }, function() {
|
||||
return elem.getBoundingClientRect().left;
|
||||
} ) :
|
||||
0
|
||||
)
|
||||
) + "px";
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user