How to make something happen when you hold your finger on a button? | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis
+ 7

How to make something happen when you hold your finger on a button?

I searched on google, and I found out I have to use mousedown and mouseup events. I was thinking to add the function inside an interval on mousedown and clearing the interval at mouseup. But I failed. I need some help. An example would help a lot. Thx.

25th Dec 2019, 8:48 PM
šŸ‡ Alex Tușinean šŸ’œ
šŸ‡ Alex Tușinean šŸ’œ - avatar
4 Respostas
+ 2
You should use touchstart and touchend events https://code.sololearn.com/WIw0Ffq5vvQH/?ref=app
25th Dec 2019, 9:32 PM
CalviÕ²
CalviÕ² - avatar
+ 3
I think I did something similar to that but then, I needed to add a click event, and everything started acting weird.
25th Dec 2019, 9:34 PM
šŸ‡ Alex Tușinean šŸ’œ
šŸ‡ Alex Tușinean šŸ’œ - avatar
+ 2
so the solution is using ontouchstart html element and set interval using JS.
27th Dec 2019, 8:54 AM
Adi Pratama
Adi Pratama - avatar
+ 1
Click event would not fired, if you hold the button in longer period.
25th Dec 2019, 10:29 PM
CalviÕ²
CalviÕ² - avatar