去掉手机浏览器自带的长按响应事件及长按提示
- 如果需要去掉手机浏览器自带的长按响应事件,则需要在css文件中增加如下代码:
.touch_action
{
-webkit-touch-callout:none;
-webkit-user-select:none;
-khtml-user-select:none;
-moz-user-select:none;
-ms-user-select:none;
user-select:none;
} - img { pointer-events: none; }
-
var timeOutEvent = 0;
$(function () {
$("#mydiv").on({
touchstart: function (e) {
timeOutEvent = setTimeout("longPress()", 200);
e.preventDefault();
},
touchmove: function () {
clearTimeout(timeOutEvent);
timeOutEvent = 0;
},
touchend: function () {
clearTimeout(timeOutEvent);
if (timeOutEvent != 0) {
alert("你这是点击,不是长按");
}
return false;
}
})
});
function longPress() {
timeOutEvent = 0;
alert("长按事件触发发");
return false;
}