Let's configure our top navbar to indicate our location on the page. We'll add Bootstrap's ScrollSpy behavior to the navbar:
Refer to Bootstrap's ScrollSpy plugin documentation at http://getbootstrap.com/javascript/#scrollspy.
index.html
in your editor.body
tag:<body data-spy="scroll" data-target=".navbar">
Now, let's animate the page scrolls that will be triggered by clicking on the navbar page anchors. This requires adding a few lines to our main.js
file:
js/main.js
.$(document).read
y(function() {
:$('#nav-main [href^=#]').click(function (e) { e.preventDefault(); var div = $(this).attr('href'), $("html, body").animate({ scrollTop: $(div).position().top }, "slow"); });
What have we done here? We have done the following using the power of jQuery:
.navbar
element that use page anchors as their targetsClick on one of the nav items and you should see it animate the scroll!