Skip to content

Commit 00a9c2e

Browse files
committed
CSS: Don't automatically add "px" to properties with a few exceptions
Fixes gh-2795 Closes gh-4055 Ref gh-4009
1 parent c4f2fa2 commit 00a9c2e

File tree

5 files changed

+133
-37
lines changed

5 files changed

+133
-37
lines changed

src/css.js

Lines changed: 5 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ define( [
55
"./var/rcssNum",
66
"./css/var/rnumnonpx",
77
"./css/var/cssExpand",
8+
"./css/isAutoPx",
89
"./css/var/getStyles",
910
"./css/var/swap",
1011
"./css/curCSS",
@@ -16,7 +17,7 @@ define( [
1617
"./core/init",
1718
"./core/ready",
1819
"./selector" // contains
19-
], function( jQuery, access, camelCase, rcssNum, rnumnonpx, cssExpand,
20+
], function( jQuery, access, camelCase, rcssNum, rnumnonpx, cssExpand, isAutoPx,
2021
getStyles, swap, curCSS, adjustCSS, addGetHookIf, support, finalPropName ) {
2122

2223
"use strict";
@@ -198,30 +199,6 @@ jQuery.extend( {
198199
}
199200
},
200201

201-
// Don't automatically add "px" to these possibly-unitless properties
202-
cssNumber: {
203-
"animationIterationCount": true,
204-
"columnCount": true,
205-
"fillOpacity": true,
206-
"flexGrow": true,
207-
"flexShrink": true,
208-
"fontWeight": true,
209-
"gridArea": true,
210-
"gridColumn": true,
211-
"gridColumnEnd": true,
212-
"gridColumnStart": true,
213-
"gridRow": true,
214-
"gridRowEnd": true,
215-
"gridRowStart": true,
216-
"lineHeight": true,
217-
"opacity": true,
218-
"order": true,
219-
"orphans": true,
220-
"widows": true,
221-
"zIndex": true,
222-
"zoom": true
223-
},
224-
225202
// Add in properties whose names you wish to fix before
226203
// setting or getting the value
227204
cssProps: {},
@@ -267,11 +244,9 @@ jQuery.extend( {
267244
return;
268245
}
269246

270-
// If a number was passed in, add the unit (except for certain CSS properties)
271-
// The isCustomProp check can be removed in jQuery 4.0 when we only auto-append
272-
// "px" to a few hardcoded values.
273-
if ( type === "number" && !isCustomProp ) {
274-
value += ret && ret[ 3 ] || ( jQuery.cssNumber[ origName ] ? "" : "px" );
247+
// If the value is a number, add `px` for certain CSS properties
248+
if ( type === "number" ) {
249+
value += ret && ret[ 3 ] || ( isAutoPx( origName ) ? "px" : "" );
275250
}
276251

277252
// background-* props affect original clone's values

src/css/adjustCSS.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
define( [
22
"../core",
3+
"./isAutoPx",
34
"../var/rcssNum"
4-
], function( jQuery, rcssNum ) {
5+
], function( jQuery, isAutoPx, rcssNum ) {
56

67
"use strict";
78

@@ -16,11 +17,11 @@ function adjustCSS( elem, prop, valueParts, tween ) {
1617
return jQuery.css( elem, prop, "" );
1718
},
1819
initial =