function increase() {
value += step;
if (max < Infinity && value > max) value = max;
$inp.val(value);
}
function decrease() {
value -= step;
if (value < min) value = min;
$inp.val(value);
}
function repeatIncrease() {
repeatTimeout = setTimeout(function () {
repeatInterval = setInterval(increase, SPIN_INTERVAL);
}, SPIN_DELAY);
}
function repeatDecrease() {
repeatTimeout = setTimeout(function () {
repeatInterval = setInterval(decrease, SPIN_INTERVAL);
}, SPIN_DELAY);
}
$el.on('click', '.spin__button_increase', increase);
$el.on('click', '.spin__button_decrease', decrease);
$el.on('mousedown', '.spin__button_increase', repeatIncrease);
$el.on('mousedown', '.spin__button_decrease', repeatDecrease);
$el.on('mouseup mouseleave', '.spin__button', () => {
clearTimeout(repeatTimeout);
clearInterval(repeatInterval);
});