jQuery-使用animate()函数重新创建slideDown()效果?
如何使用$.animate函数重新创建jQuery的$.slideDown效果?将“高度”、“边距”、“边距底部”、“paddingTop”和“paddingBottom”动画化为jQuery-使用animate()函数重新创建slideDown()效果?,jquery,jquery-effects,Jquery,Jquery Effects,如何使用$.animate函数重新创建jQuery的$.slideDown效果?将“高度”、“边距”、“边距底部”、“paddingTop”和“paddingBottom”动画化为“显示” 例如: $(...).animate({ "height": "show", "marginTop": "show", "marginBottom": "show", "paddingTop": "show", "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;
}
为什么不直接使用slideDown()?因为animate()有一个步骤选项,我可以将一个函数附加到该选项上。假设这是隐藏的show instad for
。slideUp()
?