监听html页面滚动条-滚动中-滚动停止
文章目录
$(document).ready(function(){
let top1 = 0;
let top2 = 0;
let timer = null; // 定时器
$(document).scroll(function(){
clearTimeout(timer);
timer = setTimeout(isScrollEnd, 1000);
top1 = document.documentElement.scrollTop || document.body.scrollTop;
console.log("滚动中")//滚动的时候触发
});
function isScrollEnd() {
top2 = document.documentElement.scrollTop || document.body.scrollTop;
if(top1 == top2){
console.log('滚动结束了')
}
}
});
评论
登录后参与技术讨论,分享你的经验与见解。
登录 / 注册暂无评论