From b24da33f52f8ce536ae60a6cbffeb2f5cf02bac5 Mon Sep 17 00:00:00 2001 From: John Resig Date: Sat, 5 Dec 2009 00:10:19 -0500 Subject: [PATCH] Make sure that width or height don't animate to a negative value. Fixes #3881. --- src/fx.js | 2 +- test/unit/fx.js | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/fx.js b/src/fx.js index d3a7ad4046..15fce5c3a3 100644 --- a/src/fx.js +++ b/src/fx.js @@ -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; } diff --git a/test/unit/fx.js b/test/unit/fx.js index c259a38965..5b97dc33f4 100644 --- a/test/unit/fx.js +++ b/test/unit/fx.js @@ -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);