我不知道究竟你之后,还等什么,这是一个有点猜测和快速抗旱切割,需要优化,但应该工作:
jQuery.fn.expandingMenu = function(options) {
settings = jQuery.extend({
speed: 500,
show: 10,
hideCaption: 'Hide',
showCaption: 'More'
}, options);
if (this.children('.active').length) return this;
this.each(function() {
if ($(this).children().slice(settings.show).hide().length) {
$(this).append($('<li class="toggler">' + settings.showCaption + '</li>').toggle(function() {
$(this).text(settings.hideCaption).siblings().slideDown(settings.speed);
}, function() {
$(this).text(settings.showCaption).siblings().slice(settings.show + 1).slideUp(settings.speed);
}));
}
$(this).children().hide().first().show().css({cursor:"pointer"}).toggle(function() {
$(this).siblings().slice(0, settings.show).add($(this).siblings('.toggler')).show(settings.speed);
}, function() {
$(this).siblings().hide(settings.speed);
});
});
return this;
};
$(function() {
$('ul').expandingMenu({ speed: 200, showCaption: "Gimme More" });
});
See it in action here。这个例子使它成为一个插件模型,所以你可以调用$('ul').expandingMenu()
(并链接它)像上面的例子,选择速度,显示多少,以及隐藏/显示标题。看一眼,告诉我哪些部分不太正确,从那里容易调整。
太棒了!看起来在我身上 - 谢谢尼克。我会完全测试它。 – mark 2010-03-30 19:44:37
尼克它是这样的答案,让我爱StackOverflow! – jerrygarciuh 2013-05-28 15:29:48