Skip to content

Commit

Permalink
Fix #13939: Same-unit relative animations
Browse files Browse the repository at this point in the history
(cherry picked from commit 00231d5)
  • Loading branch information
gibson042 committed May 26, 2013
1 parent bd36ea2 commit 26980c6
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/effects.js
Expand Up @@ -42,8 +42,8 @@ var fxNow, timerId,


// Update tween properties // Update tween properties
if ( parts ) { if ( parts ) {
start = tween.start = +start || +target || 0;
tween.unit = unit; tween.unit = unit;
tween.start = +start || +target || 0;
// If a +=/-= token was provided, we're doing a relative animation // If a +=/-= token was provided, we're doing a relative animation
tween.end = parts[ 1 ] ? tween.end = parts[ 1 ] ?
start + ( parts[ 1 ] + 1 ) * parts[ 2 ] : start + ( parts[ 1 ] + 1 ) * parts[ 2 ] :
Expand Down
40 changes: 40 additions & 0 deletions test/unit/effects.js
Expand Up @@ -204,6 +204,46 @@ test("animate(Hash, Object, Function)", function() {
}); });
}); });


test("animate relative values", function() {

This comment has been minimized.

Copy link
@dmethvin

dmethvin May 27, 2013

Member

Thanks! Not sure how we managed to have no coverage on this.

stop();

var value = 40,
bases = [ "%", "px", "em" ],
adjustments = [ "px", "em" ],
container = jQuery("<div></div>")
.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("<div></div>")
.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() { test("animate negative height", function() {
expect(1); expect(1);
stop(); stop();
Expand Down

0 comments on commit 26980c6

Please sign in to comment.