Skip to content

Instantly share code, notes, and snippets.

@nathanhornby
Created December 16, 2015 00:21
Show Gist options
  • Save nathanhornby/b985ff12e888d54e2698 to your computer and use it in GitHub Desktop.
Save nathanhornby/b985ff12e888d54e2698 to your computer and use it in GitHub Desktop.
Velocity.js jQuery smooth scroll to #id
/* 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