Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 8 You must be signed in to star a gist
  • Fork 5 You must be signed in to fork a gist
  • Save omurphy27/3b56f49f5054a250dbb2 to your computer and use it in GitHub Desktop.
Save omurphy27/3b56f49f5054a250dbb2 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;
});
});
@streetcoder
Copy link

nice

@aditya101099
Copy link

how do you use it?

@Akhilandan
Copy link

Thanks for your Help....

@Jbone187
Copy link

Thank you

@itssalman
Copy link

thanks

@gohanko
Copy link

gohanko commented Nov 13, 2017

That function doesn't work for me. I am using Bootstrap 4. It only works on first click. Then the clicks after that is just scrolling randomly.

@mauli1212
Copy link

nice

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment