移动端长按事件
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<script src="./js/jQuery.min.js"></script>
<style>
* {
-webkit-touch-callout:none;
-webkit-user-select:none;
-khtml-user-select:none;
-moz-user-select:none;
-ms-user-select:none;
user-select:none;
}
li{
width: 100%;
height: 100px;
background: black;
margin-bottom:10px;
}
</style>
<body id="body_id">
<div style="width:100%;">
<div style="width:100%; height:100px; background-color:#CCC;" ontouchstart="gtouchstart()" ontouchmove="gtouchmove()" ontouchend="gtouchend()">长按我</div>
</div>
<script>
var timeOutEvent=0;
function gtouchstart(){
timeOutEvent = setTimeout("longPress()",500);
return false;
};
function gtouchend(){
clearTimeout(timeOutEvent);
if(timeOutEvent!=0){
alert("你这是点击,不是长按");
}
return false;
};
function gtouchmove(){
clearTimeout(timeOutEvent);
timeOutEvent = 0;
};
function longPress(){
timeOutEvent = 0;
alert("长按事件触发发");
}
</script>
</body>
</html>