Skip to content

About

✨ Scroll to Top Using JavaScript — HTML/CSS/JS creative UI project.

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Latest commit

 

History

1 Commit

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Scroll to Top Using JavaScript

Live Demo HTML CSS JavaScript License: MIT

Runnable reconstruction of the uploaded 6.8-second tutorial video.

What is shown in the video

  • Title: Scroll to top using JavaScript
  • A JavaScript function named topFunction().
  • Safari scroll reset using document.body.scrollTop = 0.
  • Chrome, Firefox and Opera scroll reset using document.documentElement.scrollTop = 0.
  • A fixed red square button at the bottom-right of the page.
  • Button dimensions: 50 × 50 px.
  • Fixed offsets: 30 px from bottom and right.
  • CSS transitions for background color, opacity and visibility.
  • The sample webpage scrolls, and the button is shown near the bottom-right when the user scrolls down.

Readable JavaScript transcribed from the video

function topFunction() {
  document.body.scrollTop = 0; // For Safari
  document.documentElement.scrollTop = 0; // For Chrome, Firefox, Opera
}

Readable CSS transcribed from the video

#button {
  display: inline-block;
  background-color: #dc3545;
  width: 50px;
  height: 50px;
  line-height: 60px;
  text-align: center;
  border-radius: 4px;
  position: fixed;
  bottom: 30px;
  right: 30px;
  transition: background-color .3s, opacity .5s, visibility .5s;
  opacity: 0;
  z-index: 1000;
}

#button i {
  font-size: 32px;
  color: white;
}

Features implemented

  • Long sample page to test scrolling.
  • Fixed red back-to-top button.
  • Button appears after scrolling 100 px.
  • Button fades in/out using opacity and visibility.
  • Smooth scroll back to page top.
  • Safari-compatible and modern browser scroll position reset.
  • Responsive layout.
  • Accessible button label and keyboard focus.
  • No external dependencies.

Run locally

python -m http.server 8000

Open http://localhost:8000

Project structure

scroll-to-top-javascript/
├── index.html
├── style.css
├── script.js
└── README.md

Accuracy note

The JavaScript function and the readable CSS declarations above are transcribed from the video. The video does not show the full website source or all visibility-trigger logic; the sample page and scroll listener are completed as a functional reconstruction. ub.com/mrchandrayee)

📄 License

MIT License

About

✨ Scroll to Top Using JavaScript — HTML/CSS/JS creative UI project.

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages