CSS: Skip the px-appending logic for animations of non-element props

Without this change animating properties from jQuery.cssNumber on non-elements
throws an error.

Ref gh-4055
Closes gh-4061
This commit is contained in:
Michał Gołębiowski-Owczarek 2018-04-30 18:52:39 +02:00 committed by GitHub
parent 7646836577
commit f5e36bd8f2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 1 deletions

View File

@ -19,7 +19,8 @@ function adjustCSS( elem, prop, valueParts, tween ) {
unit = valueParts && valueParts[ 3 ] || ( jQuery.cssNumber[ prop ] ? "" : "px" ), unit = valueParts && valueParts[ 3 ] || ( jQuery.cssNumber[ prop ] ? "" : "px" ),
// Starting value computation is required for potential unit mismatches // Starting value computation is required for potential unit mismatches
initialInUnit = ( jQuery.cssNumber[ prop ] || unit !== "px" && +initial ) && initialInUnit = elem.nodeType &&
( jQuery.cssNumber[ prop ] || unit !== "px" && +initial ) &&
rcssNum.exec( jQuery.css( elem, prop ) ); rcssNum.exec( jQuery.css( elem, prop ) );
if ( initialInUnit && initialInUnit[ 3 ] !== unit ) { if ( initialInUnit && initialInUnit[ 3 ] !== unit ) {

11
test/unit/effects.js vendored
View File

@ -607,6 +607,17 @@ QUnit.test( "animate non-element", function( assert ) {
this.clock.tick( 200 ); this.clock.tick( 200 );
} ); } );
QUnit.test( "animate non-element's zIndex without appending \"px\"", function( assert ) {
assert.expect( 1 );
var obj = { zIndex: 0 };
jQuery( obj ).animate( { zIndex: 200 }, 200, function() {
assert.equal( obj.zIndex, 200, "The custom property should be modified without appending \"px\"." );
} );
this.clock.tick( 200 );
} );
QUnit.test( "stop()", function( assert ) { QUnit.test( "stop()", function( assert ) {
assert.expect( 4 ); assert.expect( 4 );