-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path5-TouchEvent.html
44 lines (44 loc) · 1.16 KB
/
5-TouchEvent.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
#box {
width: 70vw;
height: 70vw;
background: red;
font-size: 6vw;
color: #fff;
}
</style>
</head>
<body>
<div id="box"></div>
<script>
let box = document.querySelector("#box");
/*
- changedTouches 触发当前事件的手指列表
- targetTouches 当前元素上的手指列表
- touches 当前屏幕中的手指列表
*/
document.addEventListener("touchstart",e=>e.preventDefault(),{passive:false});
box.addEventListener("touchstart",()=>{
console.log("start");
});
box.addEventListener("touchmove",(e)=>{
box.innerHTML = `
触发当前事件手指个数:${e.changedTouches.length}<br/>
当前元素上手指个数:${e.targetTouches.length}<br/>
当前屏幕上手指个数:${e.touches.length}
`;
console.log(e,"move");
});
box.addEventListener("touchend",()=>{
console.log("end");
});
</script>
</body>
</html>