移动端的touch事件

移动端的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>

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容