Skip to content

Instantly share code, notes, and snippets.

@Janking
Created May 25, 2015 16:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Janking/604b466d1a16537df2da to your computer and use it in GitHub Desktop.
Save Janking/604b466d1a16537df2da to your computer and use it in GitHub Desktop.
函数节流
//函数节流
var throttle = function (fn,interval){
var __self = fn,
timer,
firstTime = true;
var fun = function(){
var args = arguments,
__me = this,
outerTime = firstTime;
console.log(arguments)
console.log(timer)
if(firstTime){
__self.apply(__me,args);
return firstTime = false;
}
if(timer){
return false;
}
timer = setTimeout(function(){
clearTimeout(timer);
timer = null;
__self.apply(__me,args);
}, interval||500);
};
console.log(fun)
return fun;
}
var ff = throttle(function(){
console.log(1)
},2000);
window.onresize = ff;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment