Scroll-to-Top Button using Vanilla JS

Introduction

Creating a scroll-to-top button with smooth scrolling.

Plan

  1. Detect user scroll
  2. Display scroll-to-top button after a certain amount of time
  3. Go to the top when the user clicks on it

Detect user scroll

How to detect user scroll?

Scroll logic

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Ahmadullahnikzad

Ahmadullahnikzad

17 Followers

I am a web developer who writes web development content for you to make web development easier