+ 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 Answers
+ 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