Skip to content

Instantly share code, notes, and snippets.

@jsmeltzer
Created June 13, 2017 20:31
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 jsmeltzer/e77f4ce0785fc4452c39b82b2d1c7424 to your computer and use it in GitHub Desktop.
Save jsmeltzer/e77f4ce0785fc4452c39b82b2d1c7424 to your computer and use it in GitHub Desktop.
Simple Scroll to Anchor using jQuery
// REF https://stackoverflow.com/questions/3163615/how-to-scroll-html-page-to-given-anchor-using-jquery-or-javascript
jQuery(document).ready(function($){
$(document).on('click', 'a.scroll-to', function(e) {
e.preventDefault();
scrollToAnchor( $(this).attr('href') );
});
});
function scrollToAnchor(aid){
var aTag = jQuery(aid);
jQuery('html,body').animate({scrollTop: aTag.offset().top}, 400);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment