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.
47 lines
1.2 KiB
47 lines
1.2 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>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>
|