parent
5e0cc09485
commit
03a4e816e8
@ -0,0 +1,72 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Document</title>
|
||||
</head>
|
||||
<body>
|
||||
<div class="header">
|
||||
我是头部
|
||||
</div>
|
||||
<div class="main">
|
||||
<div class="content">
|
||||
秒杀模块
|
||||
</div>
|
||||
</div>
|
||||
<!--回到顶部按钮-->
|
||||
<div id="toTop" style="position: fixed; bottom: 70px; right: 50px; border-radius: 50%; background-color: rgba(0,0,0,0.1); height: 30px;width: 30px; display: none;flex-direction: column; justify-content: center; align-items: center;">
|
||||
<img src="./assets/top.png" style="height: 20px; width: 20px;" alt="">
|
||||
</div>
|
||||
</body>
|
||||
<style>
|
||||
.header{
|
||||
position: fixed;
|
||||
top: -80px;
|
||||
left: 0;
|
||||
width: 100%;
|
||||
height: 80px;
|
||||
background-color: skyblue;
|
||||
text-align: center;
|
||||
color: #fff;
|
||||
line-height: 80px;
|
||||
font-size: 30px;
|
||||
transition: all 0.3s;
|
||||
}
|
||||
.main{
|
||||
height: 1800px;
|
||||
width: 1000px;
|
||||
background-color: pink;
|
||||
}
|
||||
.content{
|
||||
position: absolute;
|
||||
top: 500px;
|
||||
background-color: gray;
|
||||
}
|
||||
</style>
|
||||
<script>
|
||||
const content = document.querySelector('.content')
|
||||
const header = document.querySelector('.header')
|
||||
const toTop = document.querySelector('#toTop')
|
||||
|
||||
window.addEventListener('scroll',function(){
|
||||
const n = document.documentElement.scrollTop
|
||||
let viewScrollTop = document.documentElement.scrollTop
|
||||
if(n>=content.offsetTop){
|
||||
header.style.top = 0
|
||||
}else{
|
||||
header.style.top = '-80px'
|
||||
}
|
||||
if(viewScrollTop>400){
|
||||
toTop.style.display = 'flex'
|
||||
}else{
|
||||
toTop.style.display = 'none'
|
||||
|
||||
}
|
||||
})
|
||||
toTop.addEventListener('click',()=>{
|
||||
document.documentElement.scrollTop = 0
|
||||
})
|
||||
|
||||
</script>
|
||||
</html>
|
Loading…
Reference in new issue