网站:http://pegasusbus.com/ebrochure
我的菜单效果很好,但是当我点击"包裹"的下拉菜单时在导航中,在我可以选择选项之前关闭下拉列表。这只发生在移动设备上。
有谁能告诉我这里有什么事吗?
答案 0 :(得分:1)
在a
文件中,您定位导航栏内的所有navbar-toggle
标记(包括// Closes the Responsive Menu on Menu Item Click
$('.navbar-collapse ul li a').click(function() {
$('.navbar-toggle:visible').click();
});
),以便在点击任何链接时折叠移动菜单。
目前你有这个:
// Closes the Responsive Menu on Menu Item Click
$('.navbar-collapse ul li a:not(.dropdown-toggle)').click(function() {
$('.navbar-toggle:visible').click();
});
您可以使用jQuery :not() Selector
来阻止这种情况// Highlight the top nav as scrolling occurs
$('body').scrollspy({
target: '.navbar-fixed-top'
})
// Closes the Responsive Menu on Menu Item Click
$('.navbar-collapse ul li a:not(.dropdown-toggle)').click(function() {
$('.navbar-toggle:visible').click();
});
**作为旁注,如果您尚未准备就绪,则应考虑通过验证流程运行您的网站:请参阅validator.nu作为示例。
工作示例:
body {
position: relative;
}
section {
padding: 50px;
height: 500px;
}
section:nth-child(3) {
background-color: lightgreen;
}
section:nth-child(4) {
background-color: lightblue;
}
section:nth-child(5) {
background-color: darkblue;
}
section:nth-child(6) {
background-color: lightcoral;
}
section:nth-child(7) {
background-color: darkmagenta;
}
section:nth-child(8) {
background-color: lightskyblue;
}
section:nth-child(9) {
background-color: lightgoldenrodyellow;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" />
<nav class="navbar navbar-default navbar-fixed-top" id="tophead">
<div class="container-fluid">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#myNavbar">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand page-scroll" href="#">Pegasus eBrochure</a>
</div>
<div class="collapse navbar-collapse" id="myNavbar">
<ul class="nav navbar-nav navbar-right">
<li class="active"><a href="#">Home</a>
</li>
<li class="dropdown"> <a class="dropdown-toggle" data-toggle="dropdown" role="button">Packages<span class="caret"></span></a>
<ul class="dropdown-menu">
<li><a href="#deals">Vacation Deals</a>
</li>
<li><a href="#sports">Sports</a>
</li>
<li><a href="#shopping">Shopping</a>
</li>
<li><a href="#holiday">Holiday</a>
</li>
<li><a href="#circuit">Circuits</a>
</li>
</ul>
</li>
<li><a href="#about">About</a>
</li>
<li><a href="#contact">Contact</a>
</li>
<li><a href="#"><span class="glyphicon glyphicon-user"></span> Sign Up</a>
</li>
<li><a href="#"><span class="glyphicon glyphicon-log-in"></span> Login</a>
</li>
</ul>
</div>
</div>
</nav>
<section id="deals">
<h1>Vacation Deals</h1>
</section>
<section id="sports">
<h1>Sports</h1>
</section>
<section id="shopping">
<h1>Shopping</h1>
</section>
<section id="holiday">
<h1>Holiday</h1>
</section>
<section id="circuit">
<h1>Circuits</h1>
</section>
<section id="about">
<h1>About</h1>
</section>
<section id="contact">
<h1>Contact</h1>
</section>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
$(function () {
var data = [
{
text: "Group 1",
children: [
{ id: 'A1', text: 'a1'},
{ id: 'B2', text: 'b2'},
{ id: 'C3', text: 'c3'}]
},
{
text: "Group 2",
children: [
{ id: 'A2', text: 'a2'},
{ id: 'B3', text: 'b3'},
{ id: 'C1', text: 'c1'}
]
}];
$('#mySelect')
.select2({data: data, placeholder : 'Select one' });
// Toggle group on click
$('.select2')
.on('click', function(){
$('.select2-results__option').on('click', function(){
$(this).find('.select2-results__options--nested').toggle();
});
});
});
答案 1 :(得分:0)
我在下面的href="#"
行中看到您的网站缺失只是添加它将解决您的问题
<a class="dropdown-toggle" data-toggle="dropdown" role="button">Packages<span class="caret"></span></a>