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.
Sponsored by Nucleo, a free application to collect, customize and export all your icons as icon font and SVG symbols. Made by the CodyHouse folks!
Do you want to include this resource in a product offered for sale? Learn more about our Extended License
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
<!-- all your content here -->
<a href="#0" class="cd-top js-cd-top">Top</a>
The link will appear fixed on the right-side of the content. Initially it has a
visibility:hidden; and an
Both visibility and opacity are controlled through two classes:
/* the button becomes visible */
/* if the user keeps scrolling down, the button is out of focus and becomes less visible */
In our .js file, we have defined three variables to control the "Back to top" link appearance:
//browser window scroll (in pixels) after which the "back to top" link is shown var offset = 300, //browser window scroll (in pixels) after which the "back to top" link opacity is reduced offsetOpacity = 1200, //duration of the top scrolling animation (in ms) scrollDuration = 700;
offset variable will be used to toggle the class
offsetOpacity, instead, to add the
.cd-top--fade-out class. The top scrolling function is bound to the "Back to top" click event.