谢谢你,jnns。做得好!
这是您的解决方案,针对 jQuery UI 版本 1.9 进行了更新。
$.effects.effect.customSlide = function (options) {
var el = $(this),
props = ['position', 'top', 'bottom', 'left', 'right'];
// Set options
var mode = $.effects.setMode(el, options.mode || 'show'); // Set Mode
var direction = options.direction || 'left'; // Default Direction
// Adjust
$.effects.save(el, props);
el.show(); // Save & Show
$.effects.createWrapper(el).css({
overflow: 'hidden'
}); // Create Wrapper
var ref = (direction == 'up' || direction == 'down') ? 'top' : 'left';
var motion = (direction == 'up' || direction == 'left') ? 'pos' : 'neg';
var distance = options.distance || (ref == 'top' ? el.outerHeight(true) : el.outerWidth(true));
if (mode == 'show') el.parent().css('height', 0);
if (mode == 'show') el.css(ref, motion == 'pos' ? (isNaN(distance) ? "-" + distance : -distance) : distance); // Shift
// Animation
var animation = {};
animation[ref] = (mode == 'show' ? (motion == 'pos' ? '+=' : '-=') : (motion == 'pos' ? '-=' : '+=')) + distance;
el.parent().animate({
height: (mode == 'show' ? distance : 0)
}, {
queue: false,
duration: options.duration,
easing: options.easing
});
el.animate(animation, {
queue: false,
duration: options.duration,
easing: options.easing,
complete: function () {
if (mode == 'hide') el.hide(); // Hide
$.effects.restore(el, props);
$.effects.removeWrapper(el); // Restore
if (options.callback) options.callback.apply(this, arguments); // Callback
el.dequeue();
}
});
};