Skip to content

Instantly share code, notes, and snippets.

@mthchz
Created May 22, 2018 17:19
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 mthchz/14d47ef1cd0d0e49b05c8455330f9be5 to your computer and use it in GitHub Desktop.
Save mthchz/14d47ef1cd0d0e49b05c8455330f9be5 to your computer and use it in GitHub Desktop.
Scroll to anchor jQuery/JS
/* SCROLLTO ANCHOR
*******************************************************************************/
$('.js-scroll-to').on('click', function(event) {
event.preventDefault();
var link = $(this).attr('href');
var hashExpression = new RegExp("#([a-zA-Z0-9\-\_]*)$");
if( hashExpression.test(link) ){
var target = this.hash,
$target = $(target);
$('html, body').stop().animate({
'scrollTop': $target.offset().top
}, 400, 'swing');
return;
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment