手机屏幕向下滑动,banner改变样式
<!-- HTML -->
<div class="banner" :class="{'active' : headerScroll }"> banner </div>
.banner {
position: fixed;
left: 0;
top: 0;
height: 50px;
width: 100%;
line-height: 50px;
padding: 0 15px;
box-sizing: border-box;
font-size: 15px;
z-index: 10000;
text-align: center;
}
.active {
background: red;
}
data(){
return {
headerScroll:false,
timeoutRef:null
}
},
created(){
window.addEventListener('scroll', () => {
clearTimeout(this.timeoutRef);
this.timeoutRef = setTimeout(this.getValue,500)
})
}
methods:{
getValue(){
let scrollTop = window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop
scrollTop > 100 ? this.headerScroll = true : this.headerScroll = false
}
}