Skip to content

Instantly share code, notes, and snippets.

@qizhihere
Created September 11, 2015 04:43
Show Gist options
  • Save qizhihere/88014d699e4621a6651a to your computer and use it in GitHub Desktop.
Save qizhihere/88014d699e4621a6651a to your computer and use it in GitHub Desktop.
delay callback most used in keyboard events
var delay = (function(){
var timer = 0;
return function(callback, ms){
clearTimeout (timer);
timer = setTimeout(callback, ms);
};
})();
// Usage
$('input').keyup(function() {
delay(function(){
alert('Time elapsed!');
}, 1000 );
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment