diff options
author | Jason Bedard <jason+github@jbedard.ca> | 2018-03-13 23:05:33 -0700 |
---|---|---|
committer | Jason Bedard <jason+github@jbedard.ca> | 2018-03-25 00:10:23 -0700 |
commit | 73d7e6259c63ac45f42c6593da8c2796c6ce9281 (patch) | |
tree | 69aba406f72aad16877dd2b312a0a9d2da44d0a5 /src/css.js | |
parent | 2b5f5d5e90b37f4a735738a6d0b6f22affbea340 (diff) | |
download | jquery-73d7e6259c63ac45f42c6593da8c2796c6ce9281.tar.gz jquery-73d7e6259c63ac45f42c6593da8c2796c6ce9281.zip |
Dimensions: avoid fetching boxSizing when setting width/height
- this avoids forcing a reflow in some cases
Fixes #3991
Diffstat (limited to 'src/css.js')
-rw-r--r-- | src/css.js | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/src/css.js b/src/css.js index bef7c7b73..ea7302012 100644 --- a/src/css.js +++ b/src/css.js @@ -346,7 +346,12 @@ jQuery.each( [ "height", "width" ], function( i, dimension ) { set: function( elem, value, extra ) { var matches, styles = getStyles( elem ), - isBorderBox = jQuery.css( elem, "boxSizing", false, styles ) === "border-box", + scrollBoxSize = support.scrollboxSize() === styles.position, + + // To avoid forcing a reflow, only fetch boxSizing if we need it (gh-3991) + boxSizingNeeded = scrollBoxSize || extra, + isBorderBox = boxSizingNeeded && + jQuery.css( elem, "boxSizing", false, styles ) === "border-box", subtract = extra && boxModelAdjustment( elem, dimension, @@ -357,7 +362,7 @@ jQuery.each( [ "height", "width" ], function( i, dimension ) { // Account for unreliable border-box dimensions by comparing offset* to computed and // faking a content-box to get border and padding (gh-3699) - if ( isBorderBox && support.scrollboxSize() === styles.position ) { + if ( isBorderBox && scrollBoxSize ) { subtract -= Math.ceil( elem[ "offset" + dimension[ 0 ].toUpperCase() + dimension.slice( 1 ) ] - parseFloat( styles[ dimension ] ) - |