javascript - Setinterval with exponential time decrease -
i've got mousedown event setinterval. want time of intervals variable. first 1 500, sec 1 500/2 = 250, etc. tips?
$plus.mousedown(function(e) { increment(20) timeout = setinterval(function(){ increment(20) }, 500); }); $(document).mouseup(function(){ clearinterval(timeout); homecoming false; });
cheers!
edit: sorry ambiguity. want time of interval alter during mousedown. while mousedown beingness performed intervaltime should change. not every single mouse click every continuous click, , reset again.
you can't setinterval()
unless maintain clearing delay change, might write wrapper around settimeout()
accomplish similar:
function easingtimeout(delay, fn) { var id, invoker = function() { fn(); delay = math.floor(delay / 2); if (delay) { id = settimeout(invoker, delay); } else { id = null; } } // start off id = settimeout(invoker, delay); homecoming { clear: function() { if (id) { cleartimeout(id); id = null; } } }
to use:
var timeout; $plus.mousedown(function(e) { increment(20); timeout = easingtimeout(500, function() { increment(20); }); }); $(document).mouseup(function(){ timeout.clear(); homecoming false; });
javascript jquery settimeout setinterval exponential
No comments:
Post a Comment