aboutsummaryrefslogtreecommitdiffstats
path: root/src/css.js
diff options
context:
space:
mode:
authorMichał Gołębiowski-Owczarek <m.goleb@gmail.com>2018-10-08 18:25:15 +0200
committerGitHub <noreply@github.com>2018-10-08 18:25:15 +0200
commit354f6036f251a3ce9b24cd7b228b4c7a79001520 (patch)
tree065a83e9c535a56e675e03b7fcb637c6fcd876da /src/css.js
parentdae5f3ce3d2df27873d01f0d9682f6a91ad66b87 (diff)
downloadjquery-354f6036f251a3ce9b24cd7b228b4c7a79001520.tar.gz
jquery-354f6036f251a3ce9b24cd7b228b4c7a79001520.zip
CSS: Don't read styles.position in the width/height cssHook unless necessary
Current width/height cssHook reads the computed position style even if not necessary as the browser passes the scrollboxSize support test. That has been changed. This commit also makes the scrollboxSize support test in line with all others (i.e. only return true or false) and changes the variable name in the hook to make the code clearer. Fixes gh-4185 Closes gh-4187
Diffstat (limited to 'src/css.js')
-rw-r--r--src/css.js10
1 files changed, 7 insertions, 3 deletions
diff --git a/src/css.js b/src/css.js
index aea0ef2c5..cc873994b 100644
--- a/src/css.js
+++ b/src/css.js
@@ -358,10 +358,14 @@ jQuery.each( [ "height", "width" ], function( i, dimension ) {
set: function( elem, value, extra ) {
var matches,
styles = getStyles( elem ),
- scrollBoxSize = support.scrollboxSize() === styles.position,
+
+ // Only read styles.position if the test has a chance to fail
+ // to avoid forcing a reflow.
+ scrollboxSizeBuggy = !support.scrollboxSize() &&
+ styles.position === "absolute",
// To avoid forcing a reflow, only fetch boxSizing if we need it (gh-3991)
- boxSizingNeeded = scrollBoxSize || extra,
+ boxSizingNeeded = scrollboxSizeBuggy || extra,
isBorderBox = boxSizingNeeded &&
jQuery.css( elem, "boxSizing", false, styles ) === "border-box",
subtract = extra ?
@@ -376,7 +380,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 && scrollBoxSize ) {
+ if ( isBorderBox && scrollboxSizeBuggy ) {
subtract -= Math.ceil(
elem[ "offset" + dimension[ 0 ].toUpperCase() + dimension.slice( 1 ) ] -
parseFloat( styles[ dimension ] ) -