0
<!DOCTYPE html>
<html onmouseup="end()">
 <head>
    <meta charset="UTF-8">
    <script type="text/javascript">
    var counter;
    var count = 0;

          
    function start(outp)
    {
        counter = setInterval(function()
        {
          console.log(count);
          add(outp);
          count++;
        },500);
    }
    function end()
    {
    clearInterval(counter);
    }
      
      
    function add(outp)
    {
    window.document.form1.Display.value =
    window.document.form1.Display.value + outp;
    }
       </script>

 </head>
 <body >
    <form name="form1">
        <button onmousedown="start('x')"onmouseleave="end()" >Click and hold</button>
        <input type="text"name="Display"class="display"readonly>
    </form>
 </body>
</html>

Thats the snippet, the "500" is the delay between each iteration but I have no Idea how to specify the initial delay.

The button normally also has an Onclick event and I want the onmouse event to be triggered after X amount of time.

YAAAHA
  • 3
  • 3

1 Answers1

0

Try setting an initial timeout and doing your logic in there, and then also setting the interval with the same logic.

setTimeout(() => {
  console.log(count);
  add(outp);
  count++;
  counter = setInterval(() =>
    {
      console.log(count);
      add(outp);
      count++;
     }, 500);
}, initialTimoutMs); 

  
Eric Svitok
  • 792
  • 5
  • 11