javascript - While MouseDown, first slowly decrease number, then increase decreasing speed (jQuery) -
javascript - While MouseDown, first slowly decrease number, then increase decreasing speed (jQuery) -
as title suggests i'm stuck mousedown problem. want in "pseudocode"
while ("#arrowup").mousedown(function() { counter++; //one time straight when pressed if(mousedowntime > 500){ //500ms settimeout({counter++}, 75); //meaning, every 75ms counter++ }
}
i have been looking around @ stack overflow on 2 days now. , succeeded increment every 75ms, couldn't build in if(mousedowntime > 500)
-statement, while still beingness able increment counter every 75ms after 500ms.
$("#tempup").mousedown(function() { //when longer pressed, automatically faster increment temperature int = setinterval(edittemp(currtemp+1), 250); }) .mouseup(function() { clearinterval(int); numberofrepeats = 0; });
this code have of of function far. help me out? or asking question in wrong way? (non-constructive)
if understand correctly can create utilize of combination of settimeout
, setinterval
, so:
$(document).ready(function () { var temp = 0; // initial value set when clicked var = null; // timeout object var int = null; // interval object $("#tempup").on("mousedown", function () { temp++; $("#tempshow").html(temp); = settimeout(function () { int = setinterval(function () { temp++; $("#temp").html(temp); }, 75); // interval time increment temp value; every 75 ms on mouse downwards }, 500); // initial wait time after first click = 500 ms }).on("mouseup", function () { cleartimeout(to); // clear timeout clearinterval(int); // clear interval }); });
see fiddle example.
javascript jquery html timer mousedown
Comments
Post a Comment