吸顶
吸顶实际上就是当屏幕滑动的距离超过一个阈值后,盒子变更为fixed定位,判断滑动距离的代码为:
<div class="nav-bar" :class="{'is_fixed':isFixed}">
methods:{
initHeight(){
let scrollTop = window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop;
this.isFixed = scrollTop > 152? true:false;
}
},
destroyed(){
window.removeEventListener('scroll',this.initHeight,false)
}
}