Repeat mouse click function when the key is clicked
Hi friends,
I have a problem. This is my javascript code to generate of 10 next numbers around range when user will click:
- // vars
- var step = Number(100);
- var min = Number(100);
- var max = Number(1000000);
-
- // init
- $("#ActMin").attr("value", min);
- $("#ActMax").attr("value", 10*min);
-
- var x = min;
- $("#Measure").html("");
- while (x <= (10*min)) {
- $("#Measure").append("<span class=\"Value\">"+x+"</span>");
- x = x+step;
- }
-
- // script
- $("#ButtonRight").click(function() {
- var actMin = Number($("#ActMin").attr("value"));
- var actMax = Number($("#ActMax").attr("value"));
-
- if(actMax<max) {
- $("#ActMin").attr("value", actMin+step);
- $("#ActMax").attr("value", actMax+step);
- var x = Number($("#ActMin").attr("value"));
- $("#Measure").html("");
-
- while (x <= Number($("#ActMax").attr("value"))) {
- $("#Measure").append("<span class=\"Value\">"+x+"</span>");
- x = x+step;
- }
- } else {
- alert("Err");
- }
- });
and html:
- <div class="Measure" id="Measure"></div>
- <input type="hidden" name="" value="" id="ActMin" />
- <input type="hidden" name="" value="" id="ActMax" />
- <span id="ButtonRight"></span>
How to do so that when the user still is keeping the pressed key the function repeats itself? Must I use mousedown event? If so it in what way to stop repeating the function after letting go of the key?
Very thanks for answers,
Kamil
PS Sorry for my English, im from Poland ;)