1、监听滚动事件
window.addEventListener('scroll', commonHeadScroll)
2、滚动函数
commonHeadScroll = () => {
if (this.timer) {
clearTimeout(this.timer);
}
this.timer = setTimeout(() => {
let scrollTop = document.body.scrollTop || document.documentElement.scrollTop,
scrollHeight = document.body.scrollHeight || document.documentElement.scrollHeight,
clientHeight = document.body.clientHeight || document.documentElement.clientHeight,
headBottomId = document.getElementById('headBottomId'),
articleNavId = document.getElementById('articleNavId');
// console.log('commonHeadScroll=========', scrollTop, scrollHeight, clientHeight);
commonFun.lazyLoadImgFun();
commonFun.lazyLoadBgImgFun();
if (scrollTop < this.scrollTop) {
headBottomId.classList.add('active');
} else {
headBottomId.classList.remove('active');
}
this.scrollTop = scrollTop;
if (articleNavId) {
if ((scrollHeight - scrollTop - clientHeight) <= 500) {
articleNavId.classList.remove('active');
} else {
articleNavId.classList.add('active');
}
}
clearTimeout(this.timer)
}, 100);
};
3、取消监听滚动事件
window.removeEventListener('scroll', commonHeadScroll);