For a smooth scroll I use this code:
$(document).ready(function() { $(".navbar-default ul li a[href^='#']").on('click', function(e) { // prevent default anchor click behavior e.preventDefault(); // animate $('html, body').animate({ scrollTop: $(this.hash).offset().top }, 400, function() { // when done, add hash to url // (default click behaviour) window.location.hash = this.hash; }); }); When you click on a link in the address bar, #undefined added instead of the hash value of this link.