Làm cách nào để tạo lại hiệu ứng $ .slideDown của jQuery bằng cách sử dụng hàm $ .animate?
13
jQuery - tạo lại hiệu ứng slideDown () bằng cách sử dụng hàm animate ()?

01:47:11 20/03/2023
13 hữu ích 2 bình luận 9.2k xem chia sẻ
1 trả lời 1
answer ![Vũ Hạo Nhiên]()
30

20:20:19 09/07/2010
Tạo hoạt ảnh "height", "marginTop", "marginBottom", "paddingTop" và "paddingBottom" thành "show"
.
Ví dụ:
$(...).animate({
"height": "show",
"marginTop": "show",
"marginBottom": "show",
"paddingTop": "show",
"paddingBottom": "show"
});
Nguồn: mã nguồn 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;
}
30 hữu ích 1 bình luận chia sẻ
Xem nguồn: https://stackoverflow.com/questions/3216230/jquery-recreate-slidedown-effect-using-the-animate-function

Không tìm thấy câu trả lời bạn tìm kiếm? Duyệt qua các câu hỏi được gắn thẻ hỏi câu hỏi của bạn.
, hoặc Có thể bạn quan tâm

Hoạt động
Liên quan
Mới tạo