- Scroll to top snippet
- JQuery and vanilla-js version
- jQuery for the jQuery version
cargobay.scrollToTop.init();
The class '.js-scroll-to-top' is used as the javascript-hook. Place this on any element and on click there will be an animated scroll to the top of the page.
With the data-animation-duration attribute you can set the desired duration of the scroll animation. (defaults to 300ms)
<a href="#" class="js-scroll-to-top" data-animation-duration="300">Scroll to top</a>
- Latest Chrome
- Latest FireFox
- Latest Safari
- IE9 and up