简体   繁体   English

如何在 Android 浏览器中检测鼠标单击并按住?

[英]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.我正在编写一个旨在在 Android 手机和其他移动设备上查看的网页。 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.我尝试在输入按钮的 onmousedown 事件上使用 javascript function setInterval() 并在 onmouseup 事件上使用 clearInterval()。 This works perfectly when accessing the device from any browser on a PC.当从 PC 上的任何浏览器访问设备时,这非常有效。 Unfortunately, it doesn't work on my Android phone.不幸的是,它不适用于我的 Android 手机。 The button appearance does seem to change to the held state when pressed and held but the onmousedown event doesn't get called.按下并按住时,按钮的外观似乎确实更改为按住的 state 但未调用 onmousedown 事件。

Has anyone found a good way to do press-and-hold button actions that is compatible with Android devices?有没有人找到一种与 Android 设备兼容的长按按钮操作的好方法?

Check here:在这里检查:

What DOM events are available to WebKit on Android? Android 上的 WebKit 可以使用哪些 DOM 事件?

and here:和这里:

Quirksmode.org/mobile Quirksmode.org/mobile

Seems that you need to use some of the DOM or touch handlers (last one may have problems when using trackbal)似乎你需要使用一些 DOM 或触摸处理程序(最后一个在使用 trackbal 时可能会出现问题)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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