Skip to content

Instantly share code, notes, and snippets.

@patotoma
Last active August 29, 2015 13:56
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 patotoma/8799747 to your computer and use it in GitHub Desktop.
Save patotoma/8799747 to your computer and use it in GitHub Desktop.
Smooth Scroll with jQuery
$.fn.smoothscroll = function(offset, speed){
$(this).find('a').on('click', function(e){
e.preventDefault();
$('html,body').animate({scrollTop: $(this.hash).offset().top - offset}, speed);
});
};

Smooth Scroll with jQuery

$.fn.smoothscroll = function(offset, speed){
  $(this).find('a').on('click', function(e){
    e.preventDefault();
      $('html,body').animate({scrollTop: $(this.hash).offset().top - offset}, speed);
  });
};

How to use:

  • Download smoothscroll.js or smoothscroll_min.js(minified version).
  • Include the file in your html.
  • Use like following:
$(document).ready(function(){
  $('nav').smoothscroll(0, 1000);
});

You can adjust the values of offset and speed to suit your needs!

If you have any questions or innovations please leave me a comment.

patriktoma.studenthosting.sk

$.fn.smoothscroll=function(a,b){$(this).find("a").on("click",function(c){c.preventDefault();$("html,body").animate({scrollTop:$(this.hash).offset().top-a},b)})};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment