Fixes #7912. Make sure .cur() only returns 0 as fallback value when it needs to ("", auto, undefined, null).
This change makes .cur() more .cssHooks friendly. .cur() now returns the unmodified value by .css() if it isn't a number, number-alike or a value that needs a fallback to 0. This way fx.start doesn't need to be recalculated for complex values.
This commit is contained in:
parent
b9f5e2b974
commit
85d9343271
10
src/effects.js
vendored
10
src/effects.js
vendored
|
@ -185,7 +185,7 @@ jQuery.fn.extend({
|
|||
|
||||
} else {
|
||||
var parts = rfxnum.exec(val),
|
||||
start = e.cur() || 0;
|
||||
start = e.cur();
|
||||
|
||||
if ( parts ) {
|
||||
var end = parseFloat( parts[2] ),
|
||||
|
@ -336,8 +336,12 @@ jQuery.fx.prototype = {
|
|||
return this.elem[ this.prop ];
|
||||
}
|
||||
|
||||
var r = parseFloat( jQuery.css( this.elem, this.prop ) );
|
||||
return r || 0;
|
||||
var parsed,
|
||||
r = jQuery.css( this.elem, this.prop );
|
||||
// Empty strings, null, undefined and "auto" are converted to 0,
|
||||
// complex values such as "rotate(1rad)" are returned as is,
|
||||
// simple values such as "10px" are parsed to Float.
|
||||
return isNaN( parsed = parseFloat( r ) ) ? !r || r === "auto" ? 0 : r : parsed;
|
||||
},
|
||||
|
||||
// Start an animation from one number to another
|
||||
|
|
49
test/unit/effects.js
vendored
49
test/unit/effects.js
vendored
|
@ -558,21 +558,44 @@ jQuery.checkOverflowDisplay = function(){
|
|||
start();
|
||||
}
|
||||
|
||||
test("support negative values < -10000 (bug #7193)", function () {
|
||||
expect(1);
|
||||
stop();
|
||||
test("jQuery.fx.prototype.cur()", function() {
|
||||
expect(5);
|
||||
var nothiddendiv = jQuery('#nothiddendiv').css({
|
||||
color: '#ABC',
|
||||
border: '5px solid black',
|
||||
left: 'auto',
|
||||
marginBottom: '11000px'
|
||||
})[0];
|
||||
|
||||
jQuery.extend(jQuery.fx.step, {
|
||||
"marginBottom": function(fx) {
|
||||
equals( fx.cur(), -11000, "Element has margin-bottom of -11000" );
|
||||
delete jQuery.fx.step.marginBottom;
|
||||
}
|
||||
});
|
||||
equals(
|
||||
(new jQuery.fx( nothiddendiv, {}, 'color' )).cur(),
|
||||
jQuery.css( nothiddendiv,'color' ),
|
||||
"Return the same value as jQuery.css for complex properties (bug #7912)"
|
||||
);
|
||||
|
||||
jQuery("#main").css("marginBottom", "-11000px").animate({ marginBottom: "-11001px" }, {
|
||||
duration: 1,
|
||||
complete: start
|
||||
});
|
||||
strictEqual(
|
||||
(new jQuery.fx( nothiddendiv, {}, 'borderLeftWidth' )).cur(),
|
||||
5,
|
||||
"Return simple values parsed as Float"
|
||||
);
|
||||
|
||||
strictEqual(
|
||||
(new jQuery.fx( nothiddendiv, {}, 'backgroundPosition' )).cur(),
|
||||
0,
|
||||
'Return 0 when jQuery.css returns an empty string'
|
||||
);
|
||||
|
||||
strictEqual(
|
||||
(new jQuery.fx( nothiddendiv, {}, 'left' )).cur(),
|
||||
0,
|
||||
'Return 0 when jQuery.css returns "auto"'
|
||||
);
|
||||
|
||||
equals(
|
||||
(new jQuery.fx( nothiddendiv, {}, 'marginBottom' )).cur(),
|
||||
11000,
|
||||
"support negative values < -10000 (bug #7193)"
|
||||
);
|
||||
});
|
||||
|
||||
test("JS Overflow and Display", function() {
|
||||
|
|
Loading…
Reference in a new issue