需要做一个滚动后,头部固定的页面
这个用到 css 里的 fixed 就可以实现了
1 2 3 4 5 6 7 8 9 10 11
| .headDiv { position: fixed; top: 0; right: 0; bottom: 0; left: 0; width: 100%; height: 60px; border: 1px solid blue; }
|
然后监听页面滚动, 当滚动到一定数值时 切换logo 并改变 底的颜色即可
这是zanUI 官网的效果 这里拿来代码说明一下
滚动前的
1 2 3 4 5 6 7 8 9 10 11 12 13 14
| .zanui-nav { z-index: 3; height: 80px; position: fixed; width: 100%; min-width: 1024px; background-repeat: no-repeat; background-position: 20px; background: rgba(0,0,0,.2) url(https://img.yzcdn.cn/v2/image/youzanyun/zanui/pc/pc_shouye_logo1_v2.png) no-repeat 20px/76px 20px; background: #000 url(https://img.yzcdn.cn/v2/image/youzanyun/zanui/pc/pc_shouye_logo1_v2.png) no-repeat 20px/76px 20px\0; -webkit-transition: all 1.2s; -moz-transition: all 1.2s; transition: all 1.2s; }
|
滚动后的
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
| //这里多加了个类 .zanui-nav.scrolled { -webkit-box-shadow: 0 1px 4px rgba(0,0,0,.1); box-shadow: 0 1px 4px rgba(0,0,0,.1); background: #fbfbfb url(https://img.yzcdn.cn/v2/image/youzanyun/zanui/pc/pc_shouye_logo2_v2.png) no-repeat 20px/76px 20px; -webkit-transition: all 1.2s; -moz-transition: all 1.2s; transition: all 1.2s; }
.zanui-nav { z-index: 3; height: 80px; position: fixed; width: 100%; min-width: 1024px; background-repeat: no-repeat; background-position: 20px; background: rgba(0,0,0,.2) url(https://img.yzcdn.cn/v2/image/youzanyun/zanui/pc/pc_shouye_logo1_v2.png) no-repeat 20px/76px 20px; background: #000 url(https://img.yzcdn.cn/v2/image/youzanyun/zanui/pc/pc_shouye_logo1_v2.png) no-repeat 20px/76px 20px\0; -webkit-transition: all 1.2s; -moz-transition: all 1.2s; transition: all 1.2s; }
|
参考文档