main
p86outhgb 1 month ago
parent e95b4174fc
commit 0c9fab6738

@ -0,0 +1,59 @@
<!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>
Loading…
Cancel
Save