dig*_*uru 9 jquery jquery-animate
// 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 );
};
});
Run Code Online (Sandbox Code Playgroud)
我知道这是函数的简写,所以我逐渐介绍GenFX
function genFx( type, num ) {
var obj = {};
jQuery.each( fxAttrs.concat.apply([], fxAttrs.slice(0,num)), function() {
obj[ this ] = type;
});
return obj;
}
Run Code Online (Sandbox Code Playgroud)
然后是fxAttrs
fxAttrs = [
// height animations
[ "height", "marginTop", "marginBottom", "paddingTop", "paddingBottom" ],
// width animations
[ "width", "marginLeft", "marginRight", "paddingLeft", "paddingRight" ],
// opacity animations
[ "opacity" ]
],
Run Code Online (Sandbox Code Playgroud)
但我无法弄清楚这段代码是如何工作的,或者我将如何创建影响HTML宽度属性的slideLeft或slideRight.
您可以执行与 相同的slideRight操作slideUp:
$.fn.slideRight = function(options) {
var s_opt = {
speed: "slow",
callback: null
}
$.extend(s_opt, options);
return this.each(function() {
$(this).effect("slide", null,
s_opt.speed, s_opt.callback);
});
};
Run Code Online (Sandbox Code Playgroud)
小提琴: http: //jsfiddle.net/maniator/eVUsH/