+ 7
[Solved]How to make a press and hold button in HTML ??
I am working on A code now but incurring some problems in how to do that. https://code.sololearn.com/W1HytmSMVYu1/?ref=app
5 odpowiedzi
+ 10
This can be done in JavaScript with touchstart/mousedown and touchend/mouseup events. Essentially have a function that fires when the touchstart or mousedown event fires for an element that calls your movement functions on an interval (say every 100 ms). Then use the touchend and mouseup events to cancel your interval. So basically start and stop an interval that repeatedly calls your movement functions.
use touchstart and touchend for mobile devices and mousedown and mouseup for desktop compatability. You can assign both sets to do the same thing.
I implemented it here:
https://code.sololearn.com/Wplw93WTQ70j/?ref=app
+ 8
Mike Perkowski Nice job with your fix for moving the box.
I hope you don't mind... but I revised your code by consolidating logic and functions where there were patterns for reuse.
Krish I cleaned a bit on your HTML and JS related to click events on colors and shapes controls.
https://code.sololearn.com/WUVrS54WbnSg/
+ 8
David Carroll looks great! Very clean and elegant.
+ 3
Thanks a lot
+ 2
Show what you have already done