jquery实现手机端长按响应事件

来源:互联网 发布:java 打包jar 依赖库 编辑:程序博客网 时间:2024/05/17 06:35
var time = 0;//初始化起始时间$("#imgDiv").on('touchstart', '.previewImg', function(e){    e.stopPropagation();    var index=$("#imgDiv").find(".image").index($(this));    time = setTimeout(function(){    showCloseImg(index);    }, 500);//这里设置长按响应时间});$("#imgDiv").on('touchend', '.previewImg', function(e){    e.stopPropagation();    clearTimeout(time);  });function showCloseImg(index){var e=$("#imgDiv").find(".image").eq(index);$(".deleteImg").hide();e.next().show();}
如果需要去掉手机浏览器自带的长按响应事件,则需要在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;
}
                                             
0 0