Need javascript code for button press and hold

前端 未结 6 2294
庸人自扰
庸人自扰 2020-12-03 05:13

I\'d like a short smallest possible javascript routine that when a mousedown occurs on a button it first responds just like a mouseclick and then if the user keeps the butto

6条回答
  •  生来不讨喜
    2020-12-03 05:53

    When the button is pressed, call window.setTimeout with your intended time and the function x, and set the timer again at the end of x but this time with a smaller interval.

    Clear the timeout using window.clearTimeout upon release of the mouse button.

提交回复
热议问题