js、jq手机端图片长按禁止弹出默认菜单,弹出指定内容

手机端长按图片,禁止弹出系统默认菜单等内容,弹出指定内容

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
<script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script>
<img id="popUp" src="https://www.xuexiareas.com/upload/20200307/3d5cdb03e5d2e922ccc9d024e3312cc8.jpg" >
<script>
$("#popUp").on({
touchstart: function(e){
timeOutEvent = setTimeout(function(){

alert("指定内容")
},500);
e.preventDefault();
},
touchmove: function(){
clearTimeout(timeOutEvent);
timeOutEvent = 0;
e.preventDefault();
},
touchend: function(e){
clearTimeout(timeOutEvent);
if(timeOutEvent!=0){//点击
// alert("点击事件");
}
return false;
}
})
</script>
</body>
</html>

亲测效果可用


六月初字帖坊小程序 你想要的字帖模板及工具,这里都有!