导航栏的在线

main
pw5sib4uf 1 month ago
parent e94d590d1b
commit d89427dbf9

@ -0,0 +1,47 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
.box1{
position: fixed;
width: 100%;
height: 50px;
background-color: #e4e4e4;
text-align: center;
line-height: 50px;
top:-80px;
}
.box2{
width: 100%;
height: 1800px;
background-color: pink;
display: flex;
align-items: center;
}
.box3{
width: 200px;
background-color: aqua;
}
</style>
</head>
<body>
<div class="box1">我又出现了</div>
<div class="box2">
<div class="box3">滑到这里再出现</div>
</div>
<script>
const box1=document.querySelector('.box1')
const box3=document.querySelector('.box3')
window.addEventListener('scroll',function(){
const n=document.documentElement.scrollTop
box1.style.top=n>=box3.offsetTop ? 0 : '-80px'
})
</script>
</body>
</html>
Loading…
Cancel
Save