Reputation: 1
I have a One Page template, that uses 'scroll-to' nav class. Everything works, but the mobile menu won't close, and the content appears behind the menu.
If I add … data-toggle="collapse" data-target=".in" to the links … the menu will close, but I lose the 'scroll-to' function.
Does anybody know how I can combine the 'scroll-to' CLASS and the data-toggle="collapse" data-target=".in"?
Nothing I've tried has worked.
This is the current nab menu … thanks for looking!
<!-- 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 -->
Upvotes: 0
Views: 416
Reputation: 253
your HTML menu code perfect. But I think, you have to scroll sections by using JQuery. try this
Example:
$(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>
Upvotes: 0