Created
May 22, 2018 17:19
-
-
Save mthchz/14d47ef1cd0d0e49b05c8455330f9be5 to your computer and use it in GitHub Desktop.
Scroll to anchor jQuery/JS
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
/* 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