Description
#myBtn {
display: none;
position: fixed;
bottom: 100px;
right: 30px;
z-index: 99;
border: none;
outline: none;
background-color: #FAA830;
color: white;
cursor: pointer;
padding: 15px;
border-radius: 50%;
}
#myBtn:hover {
background-color: #C77905;
}
.button-up {
margin: 30px auto;
height: 70px;
width: 70px;
transition: all 0.2s linear;
}
.button-up:hover {
transform: translate3d(0, -10px, 0);
}
.button-up::after {
content: “”;
position: absolute;
left: 17px;
z-index: 11;
display: block;
width: 25px;
height: 25px;
border-top: 2px solid #fff;
border-left: 2px solid #fff;
}
.button-up::after {
top: 30px;
left: 22px;
transform: rotate(45deg);
}
// Get the button
let mybutton = document.getElementById(“myBtn”);
// When the user scrolls down 20px from the top of the document, show the button
window.onscroll = function() {scrollFunction()};
function scrollFunction() {
if (document.body.scrollTop > 20 || document.documentElement.scrollTop > 20) {
mybutton.style.display = “block”;
} else {
mybutton.style.display = “none”;
}
}
// When the user clicks on the button, scroll to the top of the document
function topFunction() {
document.body.scrollTop = 0;
document.documentElement.scrollTop = 0;
}