Smooth scrolling with jQuery

There’s plenty of jQuery libraries out there for “smooth scrolling”, but the fact is, 91.3% of them aren’t required to pull off this affect. The jQuery code below replies only on jQuery itself. Keep it simple.
1
2
3
4
5
6
7
$(document).ready(function() {
    $('a[href^="#"]').click(function(e){    
        e.preventDefault();
        $('html,body').animate({scrollTop:$(this.hash).offset().top}, 800, 'swing');
    });
});

One thought on “Smooth scrolling with jQuery

  1. Great blog! Keep it up!!! I like your style, Quick and simple blog posts are my fav! I also love that you add JSFiddle demos to your posts!

    Keep it Up!

    - Jake

Leave a Reply

Your email address will not be published. Required fields are marked *

*


7 + 3 =

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>