原生js判断手机端页面滚动停止

var topValue = 0,// 上次滚动条到顶部的距离 interval = null;// 定时器 contactsList = document.getElementById("contactsList"); contactsList.onscroll = function() { //我项目中的contactsList滚动 if(interval == null) {// 未发起时,启动定时器,1秒1执行 interval = setInterval(function () { test(); }, 1000); } topValue = contactsList.scrollTop; } function test() { //当滚动停止时,两个计算的距离会相同,此时再执行相关操作 console.log(contactsList.scrollTop,topValue); if(contactsList.scrollTop == topValue) { console.log("ok"); clearInterval(interval); interval = null; } }

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wpzpgx.html