Skip to content

Instantly share code, notes, and snippets.

@spheiros
Created April 23, 2014 03:54
Show Gist options
  • Save spheiros/11202281 to your computer and use it in GitHub Desktop.
Save spheiros/11202281 to your computer and use it in GitHub Desktop.
js typing delay
// http://stackoverflow.com/a/1909508
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