Increase/decrease buttons reacting to mousedown
by agib
HTML
<div class="price-display">9999</div>
<div class="btn-group">
<button type="button" class="btn btn-secondary price-decrease">Decrease</button>
<button type="button" class="btn btn-secondary price-increase">Increase</button>
</div>
JavaScript
var timeoutId = 0;
function decrementPriceMax(){
/*var currentPriceMax = $(".price-display").text().replace(".","");
var newPriceMax = parseInt(currentPriceMax) - 100;
var newPriceMax = newPriceMax.toString();
var firstPart = newPriceMax.substr(0,1);
var secondPart = newPriceMax.substr(1,3);
newPriceMax = firstPart + "." + secondPart;
$(".price-display").text(newPriceMax);*/
$(".price-display").text(parseInt($(".price-display").text())-100);
timeoutId = setTimeout(decrementPriceMax, 20);
}
$('.btn.price-decrease').mousedown(function() {
timeoutId = setTimeout(decrementPriceMax, 20);
}).bind('mouseup mouseleave', function() {
clearTimeout(timeoutId);
});