Scroll-to-Top Button using Vanilla JS

Introduction

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

Scroll logic

--

--

--

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

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Flow v5.1

How to Schedule Emails with Node.js

Deploy multiple sites to Firebase hosting part 1

[angular] template projection on angular(ng-content vs ng-container)

Scraping Web Apps using Direct HTTP Request

Destructuring and Optional Chaining

content here with bolded text and stuff.

FCC Local Weather App with HTML5 Geolocation and FCC Weather API

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

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

More from Medium

What does it even mean to be Asynchronous in JavaScript?

A meme depicting a confused individual

Javascript For Loop: A Complete Guide For Loops

Selecting Web Elements with Javascript using Query Selector, getElementsBy, and Dot Notation

Today’s topic: query selectors, getElementsBy, and dot notation

what is “this”? in JS