Vanilla JavaScript Scroll to Top Chris Bongers on June 13, 2020 Let's create a JavaScript powered scroll to top function. We will create a button that will sit at the right bottom of the page, and once we click ... Read full post Submit Preview Dismiss Collapse Expand easrng easrng easrng Follow Location USA Work Student at school Joined Mar 22, 2020 • Jun 13 '20 • Edited on Jun 13 • Edited Dropdown menu Copy link Hide Easier method with no JS: Add this right after the opening body tag: <a name="top"></a> For the scroll to top button use the code <a href="#top" class="scroll-top">☝️</a> Collapse Expand Darival Darival Darival Follow Joined Jun 6, 2019 • Jun 13 '20 • Edited on Jun 13 • Edited Dropdown menu Copy link Hide No need to make the target tag an anchor, a hidden div is enough Also add: html { scroll-behavior: smooth; } To make it smooth Collapse Expand Chris Bongers Chris Bongers Chris Bongers Follow Looking to get into development? As a full-stack developer I guide you on this journey and give you bite sized tips every single day 👊 Location Cape Town, South Africa Work Solution Architect at Daily Dev Tips Joined Apr 20, 2020 • Jun 15 '20 Dropdown menu Copy link Hide The smooth behaviour is a welcome addition, I've wrote an article about this method as well: daily-dev-tips.com/posts/plain-htm... Collapse Expand Zen Zen Zen Follow Mahasiswa Psikologi Email muhzaini30@gmail.com Location Samarinda Education Psikologi, TI Work Developer Android at Toko sepeda Sinar Jaya Joined Mar 25, 2019 • Jun 14 '20 Dropdown menu Copy link Hide it's not work in hash spa mode (like site.com/#read/35) Collapse Expand Chris Bongers Chris Bongers Chris Bongers Follow Looking to get into development? As a full-stack developer I guide you on this journey and give you bite sized tips every single day 👊 Location Cape Town, South Africa Work Solution Architect at Daily Dev Tips Joined Apr 20, 2020 • Jun 15 '20 Dropdown menu Copy link Hide Hey Zen, I do indeed think the Hash needs to be in the end for the browser to understand Collapse Expand Mubashir Hassan Mubashir Hassan Mubashir Hassan Follow Trying to build software! Email official.mhm13@gmail.com Location Mansehra, Pakistan Education BS Software Engineering Pronouns He/Him Work Senior Software Developer @ Kwanso Joined Dec 11, 2019 • Jun 14 '20 Dropdown menu Copy link Hide A Codepen will help a lot! Code of Conduct • Report abuse
Easier method with no JS:
Add this right after the opening body tag:
For the scroll to top button use the code
No need to make the target tag an anchor, a hidden div is enough
Also add:
To make it smooth
The smooth behaviour is a welcome addition, I've wrote an article about this method as well: daily-dev-tips.com/posts/plain-htm...
it's not work in hash spa mode (like site.com/#read/35)
Hey Zen, I do indeed think the Hash needs to be in the end for the browser to understand
A Codepen will help a lot!