我在 jsFiddle 上扔了一些东西:http: //jsfiddle.net/8TfCZ/4/
它不像 OP 回答的文章链接中演示的那样漂亮,但如果有人决定破解他们自己的方法,它可能会作为另一种方式的起点。
JS:
(function($) {
// Display a 'popover' below a element
var displayMenu = function(el) {
// Display location = (el's position + its height + 1px border)
var bottomOfEl = $(el).offset().top + $(el).height() + 1 + 'px';
// Add bottom margin to parent <ul> equivalent to popover height
$(el).parent().addClass('active');
// Display popover
$('#popover')
.hide()
.css({
'height': '0',
'top': bottomOfEl
})
.show()
.animate({'height': '80px'}, 'fast');
};
$(document.body).on('click', '.item', function(e) {
// Close all others .item elements
$('.item').not(this).removeClass('open');
// Remove bottom margin from all other .item-lists
$('.item-list').not( $(this).parent() ).removeClass('active');
// Open this
$(this).addClass('open');
// Display popover relative to this element
displayMenu(this);
});
})(jQuery);
HTML:
<div id="popover" class="popover"></div>
<ul class="item-list">
<li class="item"></li>
<li class="item"></li>
<li class="item"></li>
<li class="item"></li>
<li class="item"></li>
<li class="item"></li>
<li class="item"></li>
<li class="item"></li>
<li class="item"></li>
<li class="item"></li>
</ul>
<ul class="item-list">
<li class="item"></li>
<li class="item"></li>
<li class="item"></li>
<li class="item"></li>
<li class="item"></li>
<li class="item"></li>
<li class="item"></li>
<li class="item"></li>
<li class="item"></li>
<li class="item"></li>
</ul>
CSS:
.popover {
display: none;
position: absolute;
width: 100%;
height: 80px;
background: blue;
}
.item-list {
padding: 0;
width: 100%;
}
.item-list.active {
margin-bottom: 80px;
}
.item {
position: relative;
list-style-type: none;
display: inline-block;
width: 50px;
height: 50px;
border: 1px solid #000;
text-align: center;
padding-right: 5px;
cursor: pointer;
}
.item:before {
content: '.item';
}
.item.open:before {
content: '.open';
}
.item.open:after {
content: '';
position: absolute;
width: 0;
height: 0;
bottom: 0px;
left: 50%;
border-left: 10px solid transparent;
border-right: 10px solid transparent;
border-bottom: 10px solid blue;
margin-left: -10px;
}