简体   繁体   中英

How to detect mouse click and hold in Android browser?

I am writing a webpage that is intended to be viewed on Android phones and hopefully other mobile devices. I am going with a webpage as opposed to an App because it is more platform independent.

I would like to perform an operation continuously while the uses is clicking and holding a button on the webpage. On mobile device the operation would run continuously when they hold their finger on the button on the webpage.

I have tried using the javascript function setInterval() on the onmousedown event of my input button and clearInterval() on the onmouseup event. This works perfectly when accessing the device from any browser on a PC. Unfortunately, it doesn't work on my Android phone. The button appearance does seem to change to the held state when pressed and held but the onmousedown event doesn't get called.

Has anyone found a good way to do press-and-hold button actions that is compatible with Android devices?

Check here:

What DOM events are available to WebKit on Android?

and here:

Quirksmode.org/mobile

Seems that you need to use some of the DOM or touch handlers (last one may have problems when using trackbal)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM