Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to implement an onmousedown and onmouseup on an iPhone touch screen

I've very new to HTML/JavaScript but am learning…

I want to make a button on an iPhone that runs a JavaScript command when it is pressed and another when it is released. I tried to do this using onmousedown and onmouseup properties, but this does not work the same on iPhone.

<input type="image" onmousedown="command_press()" onmouseup="command_release()" src="images/UP-Dark.png" alt="" title="" />

Could someone please tell me how to do the same thing on the iPhone?

like image 880
user3175352 Avatar asked Jan 09 '14 01:01

user3175352


2 Answers

The equivalent for onmousedown on touchscreen devices is ontouchstart, and the equivalent of onmouseup is ontouchend.

If you would also like to detect dragging, you could use ontouchmove which is fired every time you move your finger after touching the screen.

like image 167
tckmn Avatar answered Nov 13 '22 06:11

tckmn


You might be interested in onpointerup and onpointerdown events which will work on both touch and non touch devices. Check browser support

like image 34
Zectbumo Avatar answered Nov 13 '22 05:11

Zectbumo