Visit the new improved script here! Smooth scroll to top of page (Improved!)
If you need a plain JavaScript function to add a smooth scrolling back to the top of the page, you can use this script.
- Add an id of "top" to the
<body>
tag. Like this:<body id="top">
- Add the
onclick
function to the link. Like this:<a href="#top" onclick="scrollToTop(); return false">Back to Top ↑</a>
- Then either:
- Include the JavaScript function in your markup, preferrably at the bottom before the closing
</body>
tag if possible. - Or, create a JavaScript file, place the script in it and call that file from your HTML document (either from the
</head>
section, or before the closing</body>
tag if possible.)
Since this script is not part of the UI it can load last and will not negatively affect the user experience or usability of the page.
CodePen demo here: https://codepen.io/ricardozea/pen/5f756e303d5adc25ca3876e6a81c9e57
Author: Marco Del Corno - http://thewebthought.blogspot.com/2012/06/javascript-smooth-scroll-to-top-of-page.html
No problem at all Leo. In fact, I should be the one apologizing for not understanding your point off the bat in the first place, haha.
With that said, your question merits implementation, that's a HUGE UX win if you ask me. So I'm asking for help to see if we can get your suggestion/functionality added.
Stay tunned…