davebaswel2
posted this
26 June 2019
I use the back to top button with icon here's the code
<script src="https://kit.fontawesome.com/795d9cadb0.js"></script>
<style>
myBtn1 {
cursor: pointer;
width: 32px;
height: 32px;
background-color: rgba(0, 0, 0, 0.7);
color: #999;
font-size: 20px;
text-align: center;
position: fixed;
bottom: 10px;
z-index: 10;
line-height: 1.4;
right: 10px;
right: -ms-calc(-594.5%);
}
myBtn1:hover {
background-color: #06A828;
}
<button onclick="topFunction()" id="myBtn1"><i class="fa-chevron-up fas"></i></button>
<script>
window.onscroll = function() {scrollFunction()};
function scrollFunction() {
if (document.body.scrollTop > 400 || document.documentElement.scrollTop > 400) {
document.getElementById("myBtn1").style.display = "block";
} else {
document.getElementById("myBtn1").style.display = "none";
}
}
function topFunction() {
document.body.scrollTop = 0;
document.documentElement.scrollTop = 0;
}
I use the back to top button with icon here's the code
<script src="https://kit.fontawesome.com/795d9cadb0.js"></script>
<style>
#myBtn1 {
cursor: pointer;
width: 32px;
height: 32px;
background-color: rgba(0, 0, 0, 0.7);
color: #999;
font-size: 20px;
text-align: center;
position: fixed;
bottom: 10px;
z-index: 10;
line-height: 1.4;
right: 10px;
right: -ms-calc(-594.5%);
}
#myBtn1:hover {
background-color: #06A828;
}
<button onclick="topFunction()" id="myBtn1"><i class="fa-chevron-up fas"></i></button>
<script>
window.onscroll = function() {scrollFunction()};
function scrollFunction() {
if (document.body.scrollTop > 400 || document.documentElement.scrollTop > 400) {
document.getElementById("myBtn1").style.display = "block";
} else {
document.getElementById("myBtn1").style.display = "none";
}
}
function topFunction() {
document.body.scrollTop = 0;
document.documentElement.scrollTop = 0;
}
Last edited 26 June 2019 by davebaswel2