Created
November 10, 2016 12:24
-
-
Save Yelakelly/22e06bd351514f8eb09c9ea1146e754f to your computer and use it in GitHub Desktop.
Scroll to elem - jQuery snuppet
This file contains hidden or 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
function scrollTo(item, offset){ | |
offset = offset ? offset : 0; | |
$('html, body').animate({ | |
scrollTop: $(item).offset().top - 0 | |
}, 1000); | |
} | |
$('.js-nav-link').on('click', function(e){ | |
var elem = $(this).attr('href'); | |
if(elem.match(/#.+/)){ | |
scrollTo(elem, 50); | |
return; | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment