现在,我已经解决了我的问题。(嵌套下拉和可滚动在同一个按钮)
这不是最好的方法。这是一个黑客,但对我来说效果很好。
// move sub-menu to new node
$('.dropdown-content.dropdown-nested .dropdown-content').detach().appendTo('.dropdown-block')
// dynamic offset initial
var marginTop = $('a.dropdown-button.btn').css('height')
$('.dropdown-block .dropdown-content').css('margin-top', marginTop)
$('.dropdown-content.dropdown-nested > li > a.dropdown-button').hover(function() {
var left = $('.dropdown-content.dropdown-nested').position().left
var width = $('.dropdown-content.dropdown-nested').width()
// overide left style (preserve original style needed)
$('.dropdown-block .dropdown-content').attr('style', function(idx, style) {
return style + 'left: ' + (left + width - 20) + 'px!important'
});
});
// override mouse event to fix some animation
var isDropdownHover = false;
$('a.dropdown-button, .dropdown-content').mouseenter(function() {
isDropdownHover = true;
})
$('.dropdown-content').mouseleave(function() {
// prevent main-menu fadeOut animation when mouseleave
$('.dropdown-content.dropdown-nested').stop()
// detect if mouse out of main/sub menu area and force close dropdown
isDropdownHover = false;
setTimeout(function() {
if (isDropdownHover === false)
$('.dropdown-content.dropdown-nested').fadeOut(225);
}, 100);
})
https://jsfiddle.net/L9r1ex54/8/