去掉手机浏览器自带的长按响应事件及长按提示

  1. 如果需要去掉手机浏览器自带的长按响应事件,则需要在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;
    }

  2. img { pointer-events: none; }
  3. 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;
    }

posted @ 2016-08-03 10:42  萧萧1949  阅读(1634)  评论(0编辑  收藏  举报