DEV Community

Discussion on: ๐Ÿ”Smooth Scroll-To-Top Functionality Using JavaScript [Easy Way].

Collapse
 
deathshadow60 profile image
Info Comment hidden by post author - thread only visible in this permalink
deathshadow60 • Edited

put id="top" on your top-most element.

html { scroll-behavior: smooth; }

In your stylesheet.

href="#top" for anchors that can do it without JS

location.hash = "top"; for JavaScript (if any)

This is NOT window.scrollTo's job anymore. Hell if all you want is a anchor back to the top, it's not even JavaScript's job.

Some comments have been hidden by the post's author - find out more