我有一个单页模板,使用'滚动到'导航课。一切正常,但移动菜单不会关闭,内容会显示在菜单后面。
如果我添加... data-toggle =" collapse"数据目标="。在"到链接...菜单将关闭,但我失去了滚动到'功能。
是否有人知道如何将“滚动到...”结合起来? CLASS和数据切换="崩溃"数据目标="。在"
我所尝试的一切都没有效果。
这是当前的nab菜单...感谢您的期待!
<!-- Navigation Top start -->
<nav class="navbar navbar-default navbar-fixed-top navbar-hidden navigation-top" id="navigation-top-1"
role="navigation">
<div class="container">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse"
data-target="#bs-example-navbar-collapse-1">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<!-- Logo start -->
<a class="navbar-brand scroll-to" href="#home">
<span class="va-helper"></span>
<img src="img/nav-logo-mint1.png"/>
</a>
<!-- Logo end -->
</div>
<!-- Nav-Links start -->
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul style="padding-top:15px;" class="nav navbar-nav navbar-right">
<li class="active"><a href="#home" class="scroll-to">Home</a></li>
<li><a href="#about-us" class="scroll-to">About Us</a></li>
<li><a href="#surfing-lessons" class="scroll-to">Surfing Lessons</a></li>
<li><a href="#rentals" class="scroll-to">Rentals</a></li>
<li><a href="#team" class="scroll-to">Team</a></li>
<li><a href="#contact" class="scroll-to">Contact</a></li>
<li><a href="#" class="btn btn-default navbar-btn btn-success show-appointment-modal"><i class="fa fa-calendar fa-fw"></i> Book A Lesson</a></li>
</ul>
</div>
<!-- Nav-Links end -->
</div>
</nav>
<!-- Navigation Top end -->
答案 0 :(得分:0)
您的HTML菜单代码完美无缺。但我想,你必须使用JQuery滚动部分。试试这个
示例:
$(document).ready(function(){
// jQuery for page scrolling
$('a.scroll-to').bind('click', function(event) {
var $anchor = $(this);
$('html, body').animate({
scrollTop: ($($anchor.attr('href')).offset().top - 50)
}, 1000);
event.preventDefault();
});
});
.sample-nav{
width:100%;
height:35px; position:fixed; top:0; left:0; background:#000;
}
.sample-nav a{color:#fff;
-webkit-transition: all 0.35s;
-moz-transition: all 0.35s;
transition: all 0.35s;}
.menu-bg{
background-color:red;
width:100%; height:600px;
margin-bottom:50px;
}
#menu2{background-color:green}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.0/jquery.min.js"></script>
<html>
<body>
<div class="sample-nav">
<a class="scroll-to" href="#menu1">Menu1</a>
<a class="scroll-to" href="#menu2">Menu2</a>
</div>
<div class="menu-bg" id="menu1"></div>
<div class="menu-bg" id="menu2"></div>
</body>
</html>