-
Notifications
You must be signed in to change notification settings - Fork 20.5k
Dimensions: avoid fetching boxSizing when setting width/height #4010
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
timmywil
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like it
|
|
||
| // Only fetch boxSizing if required to avoid forcing a reflow (gh-3991) | ||
| isBorderBox = ( extra || scrollBoxSize ) && | ||
| jQuery.css( elem, "boxSizing", false, styles ) === "border-box", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like what the code is doing, but the reasons could be a little more clear. Suggestion to improve that (and reduce size a little bit as well):
diff --git i/src/css.js w/src/css.js
index fc000be..d7181f4 100644
--- i/src/css.js
+++ w/src/css.js
@@ -380,8 +380,9 @@ jQuery.each( [ "height", "width" ], function( i, dimension ) {
styles = getStyles( elem ),
scrollBoxSize = support.scrollboxSize() === styles.position,
- // Only fetch boxSizing if required to avoid forcing a reflow (gh-3991)
- isBorderBox = ( extra || scrollBoxSize ) &&
+ // 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,
@@ -393,7 +394,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 ( scrollBoxSize && isBorderBox ) {
+ if ( isBorderBox && scrollBoxSize ) {
subtract -= Math.ceil(
elem[ "offset" + dimension[ 0 ].toUpperCase() + dimension.slice( 1 ) ] -
parseFloat( styles[ dimension ] ) -There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That reduces size? Interesting, I thought an extra var would do the opposite...
I agree that is clearer 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adding the var and changing the comment:
+38 +11 dist/jquery.js
= = dist/jquery.min.js
Then changing the order in the if:
raw gz Compared to last run
= -1 dist/jquery.js
= = dist/jquery.min.js
So it didn't really change the size at all (but does make it more readable, so 👍)... @gibson042 is that the results you were getting?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't remember exactly, but this looks good to me.
- this avoids forcing a reflow in some cases Fixes jquery#3991
Fixes #3991
Adds a bit of size but I think it's worth it...