Skip to content

Instantly share code, notes, and snippets.

@xsbchen
Last active December 16, 2015 07:59
Show Gist options
  • Select an option

  • Save xsbchen/5403018 to your computer and use it in GitHub Desktop.

Select an option

Save xsbchen/5403018 to your computer and use it in GitHub Desktop.
函数节流
function highThottle(fn, content, mustTime, time) {
var start = new Date();
mustTime = mustTime || 5000;
return function() {
var args = arguments;
clearTimeout(fn.timer);
var end = new Date();
if(end - start > mustTime) {
start = new Date();
clearTimeout(fn.timer);
fn.apply(content, args);
} else {
fn.timer = setTimeout(function() {
start = new Date();
fn.apply(content, args);
}, time || 200);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment