function conunt(){ console.log(1)}//停止滑动后,定时结束才执行函数处理逻辑function throttle(method,context){ clearTimeout(method.tId) method.tId = setTimeout(function(){ method.call(context); },1000)}//滑动的时候,隔一段时间,不管有没停止滑动,都要执行处理逻辑var time = +new Date();function count2(){ console.log("函数调用:"+(+new Date() - time));}var throttle2 = function(fn,delay,mustRun){ var timer = null,previous=null; return function(){ var now = +new Date(), context= this, args = arguments; if(!previous) previous = now; var remaining = now - previous; if(mustRun && remaining >= mustRun){ fn.apply(context,args); previous = now; }else{ clearTimeout(timer); timer = setTimeout(function(){ fn.apply(context,args); },delay); } }}window.onscroll = throttle2(count2,500,1000);window.onscroll = function(){ console.log(0) throttle(conunt);}