Created
April 20, 2012 09:08
-
-
Save icodejs/2427248 to your computer and use it in GitHub Desktop.
Delay the manipulation of a input value for predefined length of time
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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