$.fn.smoothscroll = function(offset, speed){
$(this).find('a').on('click', function(e){
e.preventDefault();
$('html,body').animate({scrollTop: $(this.hash).offset().top - offset}, speed);
});
};- Download
smoothscroll.jsorsmoothscroll_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
offsetandspeedto suit your needs!
If you have any questions or innovations please leave me a comment.