jQuery – 使用animate()函数重新创建slideDown()效果?

前端之家收集整理的这篇文章主要介绍了jQuery – 使用animate()函数重新创建slideDown()效果?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
如何使用$.animate函数重新创建jQuery的$.slideDown效果

解决方法

将“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",slideToggle: genFx("toggle",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;
}
原文链接:https://www.f2er.com/jquery/180920.html

猜你在找的jQuery相关文章