I've successfully implemented a fixed navigation with scrollspy and smooth scrolling:
HTML
<body data-spy="scroll" data-target=".navbar-collapse">
<!-- ---------- Navigation ---------- -->
<div class="navbar navbar-fixed-top" role="navigation">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
<span class="sr-only">Toggle navigation</span>
</button>
<a class="navbar-brand" href="index.html"> <img src="http://placehold.it/200x50"></a>
</div>
<div class="navbar-collapse collapse">
<ul class="nav navbar-nav navbar-right">
<li class="active"><a href="#home">Home</a></li>
<li><a href="#works">Works</a></li>
<li><a href="#about">About</a></li>
<li><a href="#timeline">Timeline</a></li>
<li><a href="#contact">Contact</a></li>
</ul>
</div><!--/.nav-collapse -->
</div>
</div>
<!-- ---------- /Navigation ---------- -->
JS
$(".navbar-nav li a[href^='#']").on('click', function(e) {
e.preventDefault();
var hash = this.hash;
$('html, body').animate({
scrollTop: $(this.hash).offset().top - 80
}, 1000, function(){
window.location.hash = hash;
});
});
While everything is functioning properly, there's an issue with the scrolling as it doesn't consider the offset (my nav has a height of 80px). I attempted to add "data-offset=80" but it didn't have any effect. I'm unsure about what modifications are needed in the JS to address this problem :(