- 添加监听
document.addEventListener("scroll", this.pageScroll); //监听页面滚动
pageScroll() {
if (this.timer) clearTimeout(this.timer)
this.timer = setTimeout(this.scroll(), 300)
},
scroll() {
this.$nextTick(() => {
let scrollTop = window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop;
if (scrollTop >= 52) {
this.background = '#fff'
} else {
this.background = '#F7F8FA'
}
})
},
- 移除监听
document.removeEventListener('scroll', this.pageScroll)
clearTimeout(this.timer)