一、案例说明
手机端常用的事件就是,是否长按屏幕等。如果长按则执行什么事件。
二、案例演示
三、案例代码
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<script src="js/jquery-3.2.1.min.js"></script>
<style>
.box {
width: 200px;
height: 200px;
background-color: green;
}
</style>
</head>
<body>
<div class="box"></div>
<script>
$(function() {
console.log($('.box'));
$(".box").on({
touchstart: function(e) {
//长按触发事件
timeOutEvent = setTimeout(function() {
timeOutEvent = 0;
alert("你长按了");
}, 1000)
},
touchmove: function() {
clearTimeout(timeOutEvent);
timeOutEvent = 0;
alert('移动了')
},
touchend: function() {
clearTimeout(timeOutEvent);
if (timeOutEvent != 0) {
alert("你点击了");
}
return false;
}
});
});
</script>
</body>
</html>