简体   繁体   English

防止点击触发 taphold 事件

[英]Prevent tap from firing a taphold event

In the following code I have a simple "taphold" event defined, so summon an alert with some text.在下面的代码中,我定义了一个简单的“taphold”事件,因此用一些文本召唤警报。 The problem is that a simple tap will trigger this event as well.问题是一个简单的点击也会触发这个事件。 The point is that the user has to hold the tap to proceed (in this case alert a text).关键是用户必须按住水龙头才能继续(在这种情况下,会发出一条警告文本)。

What is causing this behavior?是什么导致了这种行为?

$("#button").on("taphold", function() {
  alert("Good day, sir!");
});

So as mentioned before, a single tap will trigger this event.所以如前所述,单击将触发此事件。 How can I prevent this from happening?我怎样才能防止这种情况发生?

This works for me in Cordova Android这在 Cordova Android 中对我有用

var pressTimer

$("a").on("mouseup touchstart", function () {
    clearTimeout(pressTimer)
    // Clear timeout
    return false;
}).on("mousedown touchstart", function () {
    // Set timeout
    pressTimer = window.setTimeout(function () {
        alert("hi");
    }, 1000)
    return false;
});

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

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