jQuery-使用animate()函数重新创建slideDown()效果? [英] jQuery - recreate slideDown() effect using the animate() function?

查看:83
本文介绍了jQuery-使用animate()函数重新创建slideDown()效果?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用$ .animate函数重新创建jQuery的$ .slideDown效果?

How can I recreate jQuery's $.slideDown effect using the $.animate function?

推荐答案

将高度","marginTop","marginBottom","paddingTop"和"paddingBottom"动画化为"show".

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

例如:

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

来源:jQuery源代码.

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;
}

这篇关于jQuery-使用animate()函数重新创建slideDown()效果?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆