css实现(position:sticky)
<div>
<div class="header">
</div>
<nav>
用于显示粘性定位的头
</nav>
<div class="content">
</div>
<footer>
底部
</footer>
</div>
<style>
.header {
width:100%;
height:160px;
background:#87CEEB;
position:sticky;
top:0px;
}
nav {
width:100%;
height:100px;
background:#F98202;
}
.content {
width:100%;
background:blue;
height:1000px;
}
footer {
background:#87CEEB;
}
</style>
js
我没写demo,运用的原理就是scrollTop>0 的时候,以后再写把