$("#target").on({
touchstart: function(e) {
// 长按事件触发
timeOutEvent = setTimeout(function() {
timeOutEvent = 0;
alert('你长按了');
}, 400);
//长按400毫秒
// e.preventDefault();
},
touchmove: function() {
clearTimeout(timeOutEvent);
timeOutEvent = 0;
},
touchend: function() {
clearTimeout(timeOutEvent);
if (timeOutEvent != 0) {
// 点击事件
// location.href = '/a/live-rooms.html';
alert('你点击了');
}
return false;
}
})
本文介绍了一个使用jQuery实现的触摸事件监听案例,通过设置长按时触发的事件及取消长按时触发的点击事件。适用于需要区分长按与点击操作的移动设备应用程序中。
874

被折叠的 条评论
为什么被折叠?



