Skip to content

Instantly share code, notes, and snippets.

@shanejones
Created August 4, 2017 14:54
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 shanejones/b8902f68360addbb455c7228b7174927 to your computer and use it in GitHub Desktop.
Save shanejones/b8902f68360addbb455c7228b7174927 to your computer and use it in GitHub Desktop.
function throttle(f, delay){
var timer = null;
return function(){
var context = this, args = arguments;
clearTimeout(timer);
timer = window.setTimeout(function(){
f.apply(context, args);
},
delay || 500);
};
}
@shanejones
Copy link
Author

Use in functions like keyup to throttle the rest of the function from runniing

.keyup( throttle( function() { /* your function here */ })

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment