Skip to content

Instantly share code, notes, and snippets.

View LeoMouraIot's full-sized avatar

Leonardo Moura LeoMouraIot

View GitHub Profile

Smooth scroll to top of page

If you need a plain JavaScript function to add a smooth scrolling back to the top of the page, you can use this script.

  1. Add an id of "top" to the body
  2. Add the onclick function to the link
  3. Include the JavaScript function in your HTML file, preferrably at the bottom 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.

Author: Marco Del Corno - http://thewebthought.blogspot.com/2012/06/javascript-smooth-scroll-to-top-of-page.html