Skip to content

Commit b24da33

Browse files
committed
Make sure that width or height don't animate to a negative value. Fixes #3881.
1 parent 8d1efee commit b24da33

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

src/fx.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,7 @@ jQuery.extend( jQuery.fx, {
432432

433433
_default: function(fx){
434434
if ( fx.elem.style && fx.elem.style[ fx.prop ] != null ) {
435-
fx.elem.style[ fx.prop ] = fx.now + fx.unit;
435+
fx.elem.style[ fx.prop ] = (fx.prop === "width" || fx.prop === "height" ? Math.max(0, fx.now) : fx.now) + fx.unit;
436436
} else {
437437
fx.elem[ fx.prop ] = fx.now;
438438
}

test/unit/fx.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,15 @@ test("animate(Hash, Object, Function)", function() {
5252
});
5353
});
5454

55+
test("animate negative height", function() {
56+
expect(1);
57+
stop();
58+
jQuery("#foo").animate({ height: -100 }, 100, function() {
59+
equals( this.offsetHeight, 0, "Verify height." );
60+
start();
61+
});
62+
});
63+
5564
/* // This test ends up being flaky depending upon the CPU load
5665
test("animate option (queue === false)", function () {
5766
expect(1);

0 commit comments

Comments
 (0)