을 나는 이 조금 정확하게 당신이 후, 그래서하지 확신 추측과 빠른 rought 컷의 최적화를 필요로하지만 작동합니다 :
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()
(및 연결)을 호출하여 속도, 표시 할 수 및 숨기기/표시 캡션에 대한 옵션을 표시 할 수 있습니다. 한 부분을 들여다 보아 어느 부분이 옳지 않은지, 거기에서 쉽게 조정할 수 있는지 말해주십시오.
화려한! Nick에게 감사합니다. 나는 그것을 완전히 테스트 할 것이다. – mark
Nick 그것은 StackOverflow를 좋아하게 만드는이 하나의 답변입니다! – jerrygarciuh