Scroll to the top of a page

“Back to the top” links are everywhere, especially on mobile websites and while it’s a very simple feature,¬†and it takes no time to code… Provided you remember how to do it. I’ve done it dozens of times and yet always end up browsing the web to find that tiny piece of code whenever I need to do it again. Next time I need to, it’ll be on my blog.

Anyway, if you want an animated scroll to the top, it’s only 1 line of code, using jQuery :

$("html, body").animate({ scrollTop: 0 }, "slow");

As simple as that !

Leave a Reply

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

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>