A jQuery snippet for back to top widget

15th May 2015
Back to Blog

We web developers like to make things easier for the user, and on a long page a “Back to Top” button can save the user from a lot of extra scrolling. I use this snippet of jQuery to accomplish it, feel free to add jQuery Easing to this for more dynamic motion:

jQuery(function() {
jQuery('.toplink').click(function() {
$("html, body").animate({
scrollTop: 0
}, "slow");
return false;
});
});

Scroll to the bottom of this website to see a live example.

Tags:

Nathaniel Flick

I'm a Front End Web Developer passionate about usability. My primary specialties are HTML5, CSS3, SCSS, LESS, and jQuery and I am very familiar with Foundation and Bootstrap frameworks. I've worked on top of and with WordPress, Shopify, Rails, Python, and ASP.net/Umbraco frameworks.

Leave a Reply

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