Skip to content

Instantly share code, notes, and snippets.

@lokimeyburg
Created October 9, 2013 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 lokimeyburg/6902599 to your computer and use it in GitHub Desktop.
Save lokimeyburg/6902599 to your computer and use it in GitHub Desktop.
typewatch.js "call a function after a user has stopped typing."
// a simple function to execute a callback,
// after the user has stopped typing for a specified amount of time
var typewatch = (function(){
var timer = 0;
return function(callback, ms){
clearTimeout (timer);
timer = setTimeout(callback, ms);
};
})();
// call a function after the user has stopped typing
$('.my-input').keyup(function () {
var self = this;
typewatch(function () {
//...
// CallYourFunctionHere();
//
}, 500);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment