Skip to content

Instantly share code, notes, and snippets.

@icodejs
Created April 20, 2012 09:08
Show Gist options
  • Save icodejs/2427248 to your computer and use it in GitHub Desktop.
Save icodejs/2427248 to your computer and use it in GitHub Desktop.
Delay the manipulation of a input value for predefined length of time
var delay = (function(){
var timer = 0;
return function(callback, ms){
clearTimeout (timer);
timer = setTimeout(callback, ms);
};
}());
$('.basket-quantity').keyup(function() {
var $that = $(this);
var quantity = $that.val();
if(!isNaN(quantity) && quantity > 0 && quantity < 500) {
delay(function(){
// do some kind of calculation on the quantity
}, 1500);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment