回到顶部html代码
#topButton {
display: none;
position: fixed;
bottom: 20px;
right: 30px;
z-index: 99;
font-size: 18px;
border: none;
outline: none;
background-color: #555;
color: white;
cursor: pointer;
padding: 10px;
border-radius: 4px;
}
#topButton:hover {
background-color: #777;
}
window.onscroll = function() {scrollFunction()};
function scrollFunction() {
if (document.body.scrollTop > 20 || document.documentElement.scrollTop > 20) {
document.getElementById("topButton").style.display = "block";
} else {
document.getElementById("topButton").style.display = "none";
}
}
function goToTop() {
document.body.scrollTop = 0;
document.documentElement.scrollTop = 0;
}
版权声明:本站内容源自互联网,如有内容侵犯了你的权益,请联系删除相关内容。