使用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');
}
});
});
答案 0 :(得分:2)
尝试touchstart
和touchend
事件。
$('#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');
}
});