(Back to Top) CSS JavaScript
HTML
Code HTML à coller ou vous pouvez juste après <body>
<button onclick="topFunction()" id="myBtn" title="Go to top">Top</button>
CSS
Le code CSS à coller dans votre feuille de styles
#myBtn {
display: none;
position: fixed;
bottom: 30px;
right: 20px;
z-index: 92;
height: 5rem;
width: 5rem;
margin-bottom: 25px;
margin-right: 20px;
font-size: 15px;
font-weight: bold;
border: none;
outline: none;
background-color: #D44638;
color: white;
border: none;
color: white;
padding: 0px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 14px;
cursor: pointer;
border-radius: 100%;
}
#myBtn:hover {
background-color: #555;
}
SCRIPT
Code JavaScript à coller juste avant </body>
<script>
//Get the button
var mybutton = document.getElementById("myBtn");
window.onscroll = function() {scrollFunction()};
function scrollFunction() {
if (document.body.scrollTop > 20 || document.documentElement.scrollTop > 20) {
mybutton.style.display = "block";
} else {
mybutton.style.display = "none";
}
}
function topFunction() {
document.body.scrollTop = 0;
document.documentElement.scrollTop = 0;
}
</script>
Testé sur Smartphone Android, PC Chrome - Internet Explorer et Firefox
- 4 vues