how to scroll to top of a page automatically using javascript
// Get The Id
var topPage = document.getElementById(`top-page`)
// On Click, Scroll to the Top of Page
topPage.onclick = () => window.scrollTo({ top: 0, behavior: 'smooth' })
// On scroll, Show/Hide the button
window.onscroll = () => {
window.scrollY > 500
? (topPage.style.display = 'block')
: (topPage.style.display = 'none')
}
// CSS
body {
background-color: #111;
height:5000px;
}
#top-page {
width: 50px;
position: fixed;
right: 30px;
bottom: 30px;
cursor: pointer;
color: white;
display: none;
}
// HTML
<img id="top-page" src="https://svgshare.com/i/LW3.sv" alt="Top">how to scroll to top of a page automatically using javascript
Also in JavaScript:
- get percentage of number javascript
- array find javascript
- Aspect Ratio height react
- typescript obejct replace propertyies
- how to check if an array contains a number in javascript
- fortuna based rng js
- js how to see console day tomorrow
- update react version
- react file input
- how to push object in array using for loop javascript
- parent class and add element addclass
- git remote url change
- angular for each
- how to print a line in javascript
- replace white spaces javascript
- how to loop object javascript
- javascript remainder function
- clear input field jquery
- import img react
- How to access the request body when POSTing using Node.js and Express
- button style not working react native
- jquery var_dump array
- if undefined angular
- javascript create json object from array