gpt4 book ai didi

javascript - 如何检测触摸屏被按下超过 2 秒?

转载 作者:行者123 更新时间:2023-12-03 10:17:32 33 4
gpt4 key购买 nike

使用 Google Chrome 和 Canary。

如何检测触摸屏按下时间是否超过 2 秒? (使用鼠标可以工作,但使用真实触摸屏则失败,在 Surface pro 3 上测试)

$(document).ready(function() {

var clickstart;
var clickstop;

$(document).bind('contextmenu', function() {
console.log('Touch screen, has no right click.');
return false;
});

$(document).mousedown( function() {
return false;
});

// With USB mouse pointer it works, but with real-touch screen its not working
$('#vip_anytime').on('mousedown', function(e) {
clickstart = e.timeStamp;
}).on('mouseup', function(e) {
clickstop = e.timeStamp- clickstart;
if(clickstop >= 2000) {
console.log('>>> After 2 second of hold');
} else {
console.log('>>> Before 2 second of hold');
}
});

});

最佳答案

尝试 touchstarttouchend 事件。

    $('#vip_anytime').on('touchstart', function(e) {    
clickstart = e.timeStamp;
}).on('touchend', function(e) {
clickstop = e.timeStamp- clickstart;
if(clickstop >= 2000) {
console.log('>>> After 2 second of hold');
} else {
console.log('>>> Before 2 second of hold');
}
});

关于javascript - 如何检测触摸屏被按下超过 2 秒?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29802937/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com