按钮preSS并保持在Android的PhoneGap的行动按钮、行动、Android、preSS

2023-09-07 04:36:45 作者:月光下的浅笑

我需要preform在我的应用程序特定的操作,如果用户presses并持有几秒钟的一个按钮,如果用户的延迟耗尽之前删除按钮的手指,然后这一行动将被取消。我使用的preSS'ontouchstart事件。

I'm need to preform a specific action in my app if the user presses and holds a button for a few second, if the user removes his finger from the button before the delay runs out, then this action will be cancelled. I use 'ontouchstart' event for the press.

有什么办法,我可以做到这一点使用HTML和JavaScript?

Is there any way i can achieve this using html and javascript?

感谢。

推荐答案

下面是一个code片段来实现这一特殊要求,

Here is a code snippets to achieve this particular requirement,

var pressTimer;
$("#btnClick").mouseup(function(){
  clearTimeout(pressTimer);
  return false;
});
$("#btnClick").mousedown(function(){
  pressTimer = window.setTimeout(function() { ... your code here ...},time_delay)
  return false; 
});