How do I smoothly scroll to different anchor links?

Tips and tricks from Tamara Olson Designs

Nothing like an abrupt jump when you click on an anchor link. Get that smooth, sexy scroll with this simple piece of code.


$(function() { $('a[href*=#]:not([href=#])').click(function() { if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname) { var target = $(this.hash); target = target.length ? target : $('[name=' + this.hash.slice(1) +']'); if (target.length) { $('html,body').animate({ scrollTop: target.offset().top }, 1000); return false; } } }); });


Share Your Thoughts

About the Author

TamaraAuthorPhoto

Tamara Olson is a self-employed UX designer and WordPress developer living in New York City.

Tamara Olson Designs Case Studies