]> source.dussan.org Git - jquery.git/commitdiff
Dimensions: avoid fetching boxSizing when setting width/height
authorJason Bedard <jason+github@jbedard.ca>
Wed, 14 Mar 2018 06:05:33 +0000 (23:05 -0700)
committerJason Bedard <jason+github@jbedard.ca>
Sun, 25 Mar 2018 07:10:23 +0000 (00:10 -0700)
- this avoids forcing a reflow in some cases

Fixes #3991

src/css.js

index bef7c7b73fb132593bc56b1858c020cd94423492..ea730201219c0dfa20cedf7535657f48da81d0f2 100644 (file)
@@ -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 ] ) -