Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save krishna19/3c5082881a05874e3874b19e960602ce to your computer and use it in GitHub Desktop.
Save krishna19/3c5082881a05874e3874b19e960602ce to your computer and use it in GitHub Desktop.
Jquery Smooth Scrolling for Bootstrap Scroll Spy Nav.js
// simple smooth scrolling for bootstrap scroll spy nav
// credit http://stackoverflow.com/questions/14804941/how-to-add-smooth-scrolling-to-bootstraps-scroll-spy-function
$(".navbar-nav li a[href^='#']").on('click', function(e) {
// prevent default anchor click behavior
e.preventDefault();
// store hash
var hash = this.hash;
// animate
$('html, body').animate({
scrollTop: $(this.hash).offset().top
}, 300, function(){
// when done, add hash to url
// (default click behaviour)
window.location.hash = hash;
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment