开发者

jQuery - recreate slideDown() effect using the animate() function?

开发者 https://www.devze.com 2023-01-06 11:40 出处:网络
How can I recreate jQuery\'s 开发者_JS百科$.slideDown effect using the $.animate function?Animate\"height\", \"marginTop\", \"marginBottom\", \"paddingTop\", and \"paddingBottom\" to \"show\".

How can I recreate jQuery's 开发者_JS百科$.slideDown effect using the $.animate function?


Animate "height", "marginTop", "marginBottom", "paddingTop", and "paddingBottom" to "show".

For example:

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

Source: jQuery source code.

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

精彩评论

暂无评论...
验证码 换一张
取 消