适用环境:菜单滑动后固定,搜索框的固定
(只做全了功能,没有写完美样式,明白原理,样式可自行调整,为了区分效果,颜色反差比较明显)先看图:
下面贴上代码
吸顶容器.body {
margin: 0px !important;
padding: 0;
box-sizing: border-box;
}
.road-tab-fixed {
position: fixed;
top: 0%;
width: 100%;
}
.top {
background: #c4f8b4;
height: 50px;
}
.list {
background: #ccc;
width: 100%;
}
.list li {
height: 50px;
border-bottom: 2px solid #f00;
}
.banner {
width: 100%;
background: #c19aff;
height: 150px;
}
菜单
- 0
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 0
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
const fixedDom = $("#road-tab"),
tabclass = "road-tab-fixed";
let beforeElementScrollTop = 0;
let beforeOffsetTop = fixedDom[0].offsetTop;
//scroll节流
const throttle = (func, wait, mustRun) => {
var timeout,
s