twitter-bootstrap 如何在悬停时制作 Bootstrap 的下拉菜单?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13244067/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to make Bootstrap's dropdown on hover?
提问by Sol Orwell
How can I make twitter bootstrap's menu dropdown be on hover instead of a click?
如何使 twitter bootstrap 的菜单下拉菜单悬停而不是单击?
采纳答案by Sol Orwell
While How to make twitter bootstrap menu dropdown on hover rather than clickhas been upvoted a lot, with the newer versions of Bootstrap, no need to hack at it.
虽然如何在悬停而不是单击时制作 twitter bootstrap 菜单下拉菜单已经被很多人赞成,但对于较新版本的 Bootstrap,无需对其进行修改。
http://cameronspear.com/blog/twitter-bootstrap-dropdown-on-hover-plugin/is a replacement for the existing dropdown.js, and lets you enable on hover. No CSS modifications required.
http://cameronsspear.com/blog/twitter-bootstrap-dropdown-on-hover-plugin/是现有 dropdown.js 的替代品,并允许您在悬停时启用。无需修改 CSS。
回答by Alex Zhdanov
1.Hide dropdown-menuon mouseover.
1.Hide下拉菜单上的鼠标悬停。
$(document).ready(function() {
$('.nav li.dropdown').hover(function() {
$(this).addClass('open');
}, function() {
$(this).removeClass('open');
});
});
2.Hide dropdown-menuon click.
2.Hide下拉菜单上点击。
$(document).ready(function() {
$('.nav li.dropdown').hover(function() {
$(this).addClass('open');
});
});
回答by Yohn
heres a function I'm using to get the navbar dropdowns to slide down on hover instead of just popping in
这是我用来让导航栏下拉菜单在悬停时向下滑动而不是直接弹出的功能
$('.navbar .dropdown').hover(function() {
$(this).find('.dropdown-menu').first().stop(true, true).delay(250).slideDown();
}, function() {
$(this).find('.dropdown-menu').first().stop(true, true).delay(100).slideUp()
});
回答by ????
You can simply do this by using only css. In case of button dropdown.
您可以仅使用 css 来简单地做到这一点。在按钮下拉的情况下。
<div class="btn-group btn-hover-group">
<a href="#" id="selected" class="btn btn-default editor-submit">Action 1</a>
<a href="#" class="btn btn-default dropdown-toggle"></a>
<ul class="dropdown-menu pull-right">
<li><a href="#" id="all" class="editor-submit">Action 2</a></li>
<li><a href="#" id="matching" class="editor-submit">Action 3</a></li>
</ul>
</div>
Removed data-toggle="dropdown"from <a href="#" class="btn btn-default dropdown-toggle"></a>
删除data-toggle="dropdown"从<a href="#" class="btn btn-default dropdown-toggle"></a>
.btn-hover-group > a:hover ~ ul{
display:block;
}
.btn-hover-group > .dropdown-menu:hover{
display:block;
}
I hope this will suffice your purpose.
我希望这将满足您的目的。
回答by parag patel
You could use a bootstrap 4 like this..
你可以像这样使用引导程序 4..
<div class="dropdown">
<button class="dropbtn">Dropdown</button>
<div class="dropdown-content">
<a href="#">Link 1</a>
<a href="#">Link 2</a>
<a href="#">Link 3</a>
</div>
</div>
then define the class property value following..it should work
然后定义下面的类属性值..它应该工作
.dropbtn {
background-color: #4CAF50;
color: white;
padding: 16px;
font-size: 16px;
border: none;
}
.dropdown {
position: relative;
display: inline-block;
}
.dropdown-content {
display: none;
position: absolute;
background-color: #f1f1f1;
min-width: 160px;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
z-index: 1;
}
.dropdown-content a {
color: black;
padding: 12px 16px;
text-decoration: none;
display: block;
}
.dropdown:hover .dropdown-content {display: block;}

