-
-
Save COLABORATI/f98a31189977d6050c840af11b5ab672 to your computer and use it in GitHub Desktop.
Velocity.js jQuery smooth scroll to #id
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
/* Scroll2 | |
======================= | |
Takes one argument, `speed`. Defaults to 500. | |
Examples: | |
$('.scroll2').scroll2(); // <a href="#contact" class="scroll2">Contact me</a> | |
$('#scrollToTop').scroll2(700); // <a href="#header" id="scrollToTop">Scroll to top</a> | |
*/ | |
$.fn.scroll2 = function (speed) { | |
var destination = $(this).attr('href'); | |
$(this).on('click', function(e){ | |
e.preventDefault(); | |
$(destination).velocity('scroll',{ | |
duration: speed || 500, | |
easing: 'ease-in-out-sine' | |
}); | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment