Skip to content

Instantly share code, notes, and snippets.

@steveosoule
Created November 28, 2012 18:30
Show Gist options
  • Save steveosoule/4163072 to your computer and use it in GitHub Desktop.
Save steveosoule/4163072 to your computer and use it in GitHub Desktop.
JavaScript - Delay Function
var delay = (function(){
var timer = 0;
return function(callback, ms){
clearTimeout (timer);
timer = setTimeout(callback, ms);
};
})();
$('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