Make sure that width or height don't animate to a negative value. Fixes #3881.
authorJohn Resig <jeresig@gmail.com>
Sat, 5 Dec 2009 05:10:19 +0000 (00:10 -0500)
committerJohn Resig <jeresig@gmail.com>
Sat, 5 Dec 2009 05:10:19 +0000 (00:10 -0500)
src/fx.js
test/unit/fx.js

index d3a7ad4..15fce5c 100644 (file)
--- 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;
                        }
index c259a38..5b97dc3 100644 (file)
@@ -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);