2010-07-09 56 views

回答

29

将动画“height”,“marginTop”,“marginBottom”,“paddingTop”和“paddingBottom”设置为"show"

例如:

$(...).animate({ 
    "height": "show", 
    "marginTop": "show", 
    "marginBottom": "show", 
    "paddingTop": "show", 
    "paddingBottom": "show" 
}); 

来源:jQuery的源代码。

fxAttrs = [ 
    // height animations 
    [ "height", "marginTop", "marginBottom", "paddingTop", "paddingBottom" ], 
    // width animations 
    [ "width", "marginLeft", "marginRight", "paddingLeft", "paddingRight" ], 
    // opacity animations 
    [ "opacity" ] 
]; 
... 

jQuery.each({ 
    slideDown: genFx("show", 1), 
    slideUp: genFx("hide", 1), 
    slideToggle: genFx("toggle", 1), 
    fadeIn: { opacity: "show" }, 
    fadeOut: { opacity: "hide" } 
}, function(name, props) { 
    jQuery.fn[ name ] = function(speed, callback) { 
     return this.animate(props, speed, callback); 
    }; 
}); 
... 

function genFx(type, num) { 
    var obj = {}; 

    jQuery.each(fxAttrs.concat.apply([], fxAttrs.slice(0,num)), function() { 
     obj[ this ] = type; 
    }); 

    return obj; 
} 
+0

谢谢,作品:D – Alex 2010-07-09 20:25:23

+1

+1因为这正是我刚才发现的。 – TNi 2010-07-09 20:30:39

+0

假设这将隐藏'.slideUp()'show的instad? – 2015-03-20 14:24:51