You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
chunagkou/页面指示器部分.html

59 lines
1.5 KiB

1 month ago
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>页面指示器部分</title>
</head>
<body>
<style>
.container{
width: 100%;
height: 2000px;
}
.back-to-top{
position: fixed;
bottom: 100px;
right: 100px;
width: 80px;
height: 80px;
background-color: #000;
color: #fff;
border-radius: 50%;
display: flex;
justify-content: center;
align-items: center;
cursor: pointer;
opacity: 0;
transition: opacity 0.3s ease-in-out;
}
h1{
font-size: 50px;
text-align: center;
}
</style>
<div class="container">
<h1>Back To Top</h1>
<div class="back-to-top">lll1</div>
</div>
<script>
const backToTopBtn = document.querySelector('.back-to-top');
window.addEventListener('scroll', () => {
if (window.scrollY > 300) {
backToTopBtn.style.opacity = 1;
} else {
backToTopBtn.style.opacity = 0;
}
});
backToTopBtn.addEventListener('click', () => {
window.scrollTo({
top: 0,
behavior:'smooth'
});
});
</script>
</body>
</html>