back to top preview
May 26, 2014 | 423 Feedbacks

Back to top

This "Back to top" link allows users to smoothly scroll back to the top of the page. It's a little detail which enhances navigation experience on website with long pages.
Browser support
  • ie
  • Chrome
  • Firefox
  • Safari
  • Opera
9+

This resource is suitable for website with lots of page content. The link fades in on the right-hand side of the content area, after the browser window has been scrolled beyond a certain point, and remains fixed during scrolling.
If users keeps on scrolling, the button nicely reduces its opacity to be less distracting during navigation.

Creating the structure

We inserted the “Back to top” link at the bottom of our content, before the closing tag.

Adding style

The link will appear fixed on the right-side of the content. Initially it has a visibility:hidden; and an opacity:0;.
Both visibility and opacity are controlled through two classes: .cd-is-visible and .cd-fade-out.

These classes are added (or removed) to the “Back to top” link using jQuery.

Events handling

In our .js file, we have defined three variables to control the “Back to top” link appearance:

The offset variable will be used to toggle the class .cd-is-visible; the offset_opacity, instead, to add the .cd-fade-out class.
The top scrolling function is implemented using the jQuery .animate() method, and bound to the “Back to top” click event.

Changelog

May 26, 2014
  • Resource released by CodyHouse

Claudia Romano

Web developer, fan of The Big Bang Theory and good food. Co-founder of CodyHouse and Nucleo. You can follow her on Twitter.