From 00231d5d94d3374d53bfe79e04ba253250c73087 Mon Sep 17 00:00:00 2001 From: Richard Gibson Date: Sun, 26 May 2013 16:02:32 -0400 Subject: [PATCH] Fix #13939: Same-unit relative animations --- src/effects.js | 2 +- test/unit/effects.js | 40 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/src/effects.js b/src/effects.js index 982365128..b03036ce3 100644 --- a/src/effects.js +++ b/src/effects.js @@ -42,8 +42,8 @@ var fxNow, timerId, // Update tween properties if ( parts ) { + start = tween.start = +start || +target || 0; tween.unit = unit; - tween.start = +start || +target || 0; // If a +=/-= token was provided, we're doing a relative animation tween.end = parts[ 1 ] ? start + ( parts[ 1 ] + 1 ) * parts[ 2 ] : diff --git a/test/unit/effects.js b/test/unit/effects.js index a23ff2cca..fc40e49d2 100644 --- a/test/unit/effects.js +++ b/test/unit/effects.js @@ -208,6 +208,46 @@ test("animate(Hash, Object, Function)", function() { }); }); +test("animate relative values", function() { + stop(); + + var value = 40, + bases = [ "%", "px", "em" ], + adjustments = [ "px", "em" ], + container = jQuery("
") + .css({ position: "absolute", height: "50em", width: "50em" }), + animations = bases.length * adjustments.length; + + expect( 2 * animations ); + + jQuery.each( bases, function( _, baseUnit ) { + jQuery.each( adjustments, function( _, adjustUnit ) { + var base = value + baseUnit, + adjust = { height: "+=2" + adjustUnit, width: "-=2" + adjustUnit }, + elem = jQuery("
") + .appendTo( container.clone().appendTo("#qunit-fixture") ) + .css({ + position: "absolute", + height: base, + width: value + adjustUnit + }), + baseScale = elem[ 0 ].offsetHeight / value, + adjustScale = elem[ 0 ].offsetWidth / value; + + elem.css( "width", base ).animate( adjust, 100, function() { + equal( this.offsetHeight, value * baseScale + 2 * adjustScale, + baseUnit + "+=" + adjustUnit ); + equal( this.offsetWidth, value * baseScale - 2 * adjustScale, + baseUnit + "-=" + adjustUnit ); + + if ( --animations === 0 ) { + start(); + } + }); + }); + }); +}); + test("animate negative height", function() { expect(1); stop(); -- 2.39.5