var throttle = {
switch:false,
timer:100,
process:function(method,context){
var self = this;
if(self.switch){
return;
}
self.switch = true;
setTimeout(function(){
self.switch = false;
method.call(context);
},self.timer);
}
}
Created
January 3, 2016 07:59
-
-
Save ghostcode/dc20e0a8f76b73ca51de to your computer and use it in GitHub Desktop.
节流函数对高频操作限制调用次数,以此提高性能
function throttle(method,context){
clearTimeout(method.flag);
method.flag = setTimeout(function(){
method.call(context);
},100);
}
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment