添加定时器,每次滚动事件先清除上个定时器,再添加新的定时器,比如说,浏览器3秒没发生滚动,3秒后则会触发定时器回调事件,进而获取到没有滚动事件。
mounted() {
window.addEventListener('scroll', this.handleScroll);
},
handleScroll() {
const scrollTop = window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop;
const titleTop = document.querySelectorAll('.c-panel-heading')[1].offsetTop;
clearTimeout(countTimer);
// 浏览器3秒内未滚动 则停止计时
countTimer = setTimeout(this.isScrollEnd, 3000);
this.taskPos.startScrollTop = parseInt(scrollTop);
},
isScrollEnd() {
const scrollTop = window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop;
this.taskPos.endScrollTop = parseInt(scrollTop);
if (this.taskPos.startScrollTop === this.taskPos.endScrollTop) {
// 获取到不滚动状态
// 业务逻辑
this.taskView.stopCountDown = true;
}
},