Runnable reconstruction of the uploaded 6.8-second tutorial 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.
function topFunction() {
document.body.scrollTop = 0; // For Safari
document.documentElement.scrollTop = 0; // For Chrome, Firefox, Opera
}#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;
}- 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.
python -m http.server 8000scroll-to-top-javascript/
├── index.html
├── style.css
├── script.js
└── README.md
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)