Created
June 13, 2017 20:31
-
-
Save jsmeltzer/e77f4ce0785fc4452c39b82b2d1c7424 to your computer and use it in GitHub Desktop.
Simple Scroll to Anchor using jQuery
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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