Delay keyup
Executing a function after the user has stopped typing for a specified amount of time.
http://stackoverflow.com/questions/1909441/jquery-keyup-delay
HTML
<input type="text" />
<div>
</div>
JavaScript
var delay = (function() {
var timer = 0;
return function(callback, ms) {
// reset the previous setTimeout
clearTimeout(timer);
timer = setTimeout(callback, ms);
};
})();
$('input').keyup(function() {
var typing = true;
delay(function() {
typing = false;
console.log('time elapsed');
$('div').append('<br/>delayed ');
}, 1000)
if(typing){
$('div').append('<br/>typing ');
}
});