You cannot do this with setInterval() unless you save the cleanup to change the delay, so you can write a wrapper around setTimeout() to do something like this:
function easingTimeout(delay, fn) { var id, invoker = function() { fn(); delay = Math.floor(delay / 2); if (delay) { id = setTimeout(invoker, delay); } else { id = null; } }
For use:
var timeout; $plus.mousedown(function(e) { increment(20); timeout = easingTimeout(500, function() { increment(20); }); }); $(document).mouseup(function(){ timeout.clear(); return false; });
Ja͢ck source share