我看过source code in jquery for slideup ...
// Generate shortcuts for custom animations
jQuery.each({
slideDown: genFx("show", 1),
slideUp: genFx("hide", 1),
slideToggle: genFx("toggle", 1),
fadeIn: { opacity: "show" },
fadeOut: { opacity: "hide" },
fadeToggle: { opacity: "toggle" }
}, function( name, props ) {
jQuery.fn[ name ] = function( speed, easing, callback ) {
return this.animate( props, speed, easing, callback );
};
});
我知道这是函数的简写,所以我继续了解 GenFX
function genFx( type, num ) {
var obj = {};
jQuery.each( fxAttrs.concat.apply([], fxAttrs.slice(0,num)), function() {
obj[ this ] = type;
});
return obj;
}
然后是 fxAttrs
fxAttrs = [
// height animations
[ "height", "marginTop", "marginBottom", "paddingTop", "paddingBottom" ],
// width animations
[ "width", "marginLeft", "marginRight", "paddingLeft", "paddingRight" ],
// opacity animations
[ "opacity" ]
],
但我就是不明白这段代码是如何工作的,或者我将如何创建一个影响 HTML 宽度属性的 slipLeft 或 slipRight。
最佳答案
您可以使用:
$('div').animate({ width: 'show' }); // slideLeft
$('div').animate({ width: 'hide' }); // slideRight
演示地址:jsFiddle .
关于jquery - SlideUp() 在 jQuery 中如何工作?我正在尝试制作自己的slideRight(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6154353/