Skip to content

Commit

Permalink
Make sure that width or height don't animate to a negative value. Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
jeresig committed Dec 5, 2009
1 parent 8d1efee commit b24da33
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/fx.js
Expand Up @@ -432,7 +432,7 @@ jQuery.extend( jQuery.fx, {

_default: function(fx){
if ( fx.elem.style && fx.elem.style[ fx.prop ] != null ) {
fx.elem.style[ fx.prop ] = fx.now + fx.unit;
fx.elem.style[ fx.prop ] = (fx.prop === "width" || fx.prop === "height" ? Math.max(0, fx.now) : fx.now) + fx.unit;
} else {
fx.elem[ fx.prop ] = fx.now;
}
Expand Down
9 changes: 9 additions & 0 deletions test/unit/fx.js
Expand Up @@ -52,6 +52,15 @@ test("animate(Hash, Object, Function)", function() {
});
});

test("animate negative height", function() {
expect(1);
stop();
jQuery("#foo").animate({ height: -100 }, 100, function() {
equals( this.offsetHeight, 0, "Verify height." );
start();
});
});

/* // This test ends up being flaky depending upon the CPU load
test("animate option (queue === false)", function () {
expect(1);
Expand Down

0 comments on commit b24da33

Please sign in to comment.