1

Is it possible to press and hold down (depress) two or more html buttons simultaneously on a touch screen with button background changing colour to red to indicate the pressed state? When the button or buttons are released, they should change back to their ordinary background colour.

I'm making a html & javascript game that fires bullets at a speed dependent on how long you hold down the buttons. I can change the colour of a single button's background using CSS as here: How to change color of button in active state using inline CSS?

I'm wondering if it's possible to achieve the above goals using html buttons or if I should make my own custom sort of button based on, say, html labels.

The ideal solution would depress a button when touched and held or when a number key on the keyboard is pressed and held.

So for example, button one would show a pressed state on a desktop while the user presses the 1 keyboard button or presses the html button on the screen with the mouse. Or a mobile phone or tablet user would press button one when they touch the button on the screen and hold it down. But I want this feature on two or more buttons. Thanks.

PS: The button's automatic text selection can be disabled using this technique: Prevent text selection from <button> element

keithphw
  • 350
  • 1
  • 4
  • 14

0 Answers0