Skip to content

Instantly share code, notes, and snippets.

@COLABORATI
Forked from nathanhornby/scroll2.js
Created June 28, 2016 21:12
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 COLABORATI/f98a31189977d6050c840af11b5ab672 to your computer and use it in GitHub Desktop.
Save COLABORATI/f98a31189977d6050c840af11b5ab672 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