0
(Coding help) How to add a "onhold" like attribute to input
Like onclick works on single click but a attribute like onhold (not exist in reality) I that will work (execute a function) untill i release the button.... PLZZZ help 🙏 I want it for my game Check out this 👇👇👇👇👇👇👇👇 https://code.sololearn.com/W64tUAoDfnNz/?ref=app
6 Réponses
+ 5
add event listeners to the element
touchstart
mousedown
touchend
mouseup
Then point touchstart and mousedown to the same event function. In this function use a while loop to continue doing what you want while pressed. Use a boolean variable to control the loop that is set to true from the touchstart/mousedown event. Then use the touchend/mouseup event function to change the boolean to false stopping the loop when the element is no longer pressed.
+ 4
Abhay Check this code and let me know whether, you've understood. If not, I'll give another simple example :))
https://code.sololearn.com/Wt8ro5u9Rld7/?ref=app
However, don't delete your question after you get the answer. This is so ungrateful :/
+ 3
Abhay here are a couple of links that might help you out.
https://www.kirupa.com/html5/press_and_hold.htm
https://stackoverflow.com/questions/79816/need-javascript-code-for-button-press-and-hold
There are a few different approaches. Arb Rahim Badsa code is a pretty decent example. You can also check out this code.
https://code.sololearn.com/WU0W04O7zpVY/?ref=app
- 1
Give me an working example to clear my doubts p, lzzzz