移动端的touch事件
<!DOCTYPE html>
<html>
<head>
<title></title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=no">
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
.box {
height: 100px;
background: yellowgreen;
font-size: 32px;
text-align: center;
width: 33%;
float: left;
border: white 2px solid;
}
</style>
</head>
<div class="box"></div>
<div class="box"></div>
<div class="box"></div>
<div class="box"></div>
<div class="box"></div>
<div class="box"></div>
<div class="box"></div>
<div class="box"></div>
<div class="box"></div>
<body>
</body>
<script type="text/javascript">
// touch事件有
// touchstart
// touchmove
// touchend
// 事件对象中的三个主要属性
// touches 屏幕上出点的信息
// targetTouches 事件标签上的触电信息
// changedTouches 标签上发生状态表换的触电信息
var div = document.querySelector(".box"),
date;
var i = 1;
document.body.addEventListener("touchstart", function(e) {
e.target.style.background = 'red';
e.target.innerText = i++;
// innerText += e.touches.length+"|"+e.tergetTouches.length;
// date = new Date();
}, false);
div.addEventListener("touchmove", function(e) {
this.innerText = e.touches.length + "|" + e.targetTouches.length + "|" + e.changedTouches.length;
// console.log(e);
}, false);
div.addEventListener("touchsend", function(e) {
// console.log(e);
}, false);
div.onclick = function() {
// console.log((new Date()) - date);
}
</script>
</html>