我有正在进行悬停的自举水平菜单。是否可以添加淡入淡出效果?我试着使用fadeIn()
和fadeOut()
,但它会提示菜单。
以下是示例:Bootply
答案 0 :(得分:1)
试试这个
JQUERY
$('[data-toggle=collapse]').hover(function (e) {
$('[data-toggle=collapse]').parent('li').removeClass('active');
$(this).parent('li').toggleClass('active');
$($(this).data('target')).collapse('show').fadeIn(fast);
});
$('.collapse').on('shown.bs.collapse', function (e) {
$('.collapse').not(this).removeClass('in').fadeOut(fast);
});
CSS
.navbar {
margin-bottom:-1px;
border-radius:0;
}
#submenu {
background-color: #e7e7e7;
margin-bottom:20px;
}
.collapsing {
display:none;
}
我唯一改变的是快速消退并快速消失......
请更多适应和fadeIn / fadeOut属性的属性在这里是一个很好的链接
答案 1 :(得分:1)
如果您在顶部菜单中使用标签,我认为它与Bootstrap更加一致:
<div class="container">
<div class="row">
<ul class="nav nav-tabs pull-right" id="myTab" role="tablist">
<li class="active"><a href="#one" role="tab" data-toggle="tab">One</a></li>
<li><a href="#two" role="tab" data-toggle="tab">Two</a></li>
<li><a href="#three" role="tab" data-toggle="tab">Three</a></li>
</ul>
</div>
<div class="row">
<div class="tab-content">
<div class="tab-pane fade in active pull-right" id="one">
<nav class="navbar navbar-default pull-right submenu" role="navigation">
<ul class="nav navbar-nav in" id="one-nav">
<li><a href="#" id="">One sub 1</a></li>
<li><a href="#" id="">One sub 2</a></li>
<li><a href="#" id="">One sub 3</a></li>
<li><a href="#" id="">One sub 4</a></li>
</ul>
</nav>
</div>
<div class="tab-pane fade pull-right" id="two">
<nav class="navbar navbar-default pull-right submenu" role="navigation">
<ul class="nav navbar-nav in" id="two-nav">
<li><a href="#" id="">Two sub 1</a></li>
<li><a href="#" id="">Two sub 2</a></li>
</ul>
</nav>
</div>
<div class="tab-pane fade pull-right" id="three">
<nav class="navbar navbar-default pull-right submenu" role="navigation">
<ul class="nav navbar-nav in" id="three-nav">
<li><a href="#" id="">Three sub 1</a></li>
<li><a href="#" id="">Three sub 2</a></li>
<li><a href="#" id="">Three sub 3</a></li>
</ul>
</nav>
</div>
</div>
</div>
</div>
然后只需点击悬停:
$('a','.nav-tabs > li').hover(function(){
$(this).trigger('click');
});
// The following addresses the problem listed in the comment below
$('a[data-toggle="tab"]').on('shown.bs.tab', function (e) {
$('.tab-pane').not($(this).attr('href')).removeClass('active');
});
请参阅bootply here。