Skip to content

Commit c40b12a

Browse files
committed
CSS: Protect against getBoundingClientRect exceptions
Ref 487d5ca Ref 6df3990
1 parent b94af72 commit c40b12a

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

src/css.js

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -437,12 +437,21 @@ jQuery.cssHooks.marginRight = addGetHookIf( support.reliableMarginRight,
437437
jQuery.cssHooks.marginLeft = addGetHookIf( support.reliableMarginLeft,
438438
function( elem, computed ) {
439439
if ( computed ) {
440-
return ( parseFloat( curCSS( elem, "marginLeft" ) ) ||
441-
elem.getBoundingClientRect().left -
442-
swap( elem, { marginLeft: 0 }, function() {
443-
return elem.getBoundingClientRect().left;
444-
} )
445-
) + "px";
440+
return (
441+
parseFloat( curCSS( elem, "marginLeft" ) ) ||
442+
443+
// Support: IE<=11+
444+
// Running getBoundingClientRect on a disconnected node in IE throws an error
445+
// Support: IE8 only
446+
// getClientRects() errors on disconnected elems
447+
( jQuery.contains( elem.ownerDocument, elem ) ?
448+
elem.getBoundingClientRect().left -
449+
swap( elem, { marginLeft: 0 }, function() {
450+
return elem.getBoundingClientRect().left;
451+
} ) :
452+
0
453+
)
454+
) + "px";
446455
}
447456
}
448457
);

0 commit comments

Comments
 (0)