posts - 83,  comments - 2,  views - 35311

touchStart

touchMove

touchEnd

 


1. 如果点击屏幕,会触发touchStart
,touchEnd,click事件
2. 如果点击屏幕并且有划动,会触发touchStart
,touchMove,touchEnd事件
3. touchmove和click是相斥
4. 在移动端点击两下屏幕, 会有缩放,点了第一下需要等待第二下, 所以click事件会有延迟300毫秒
5. 如果第一层touchstart事件隐藏了, 第二层如果有click事件,就会发生点透现象,e.preventDefault可以阻止浏览器默认行为, 在touchStart函数中可以使用e.preventDefault阻止click事件

6. 在头部增加禁用缩放, 经测试click事件延迟100毫秒左右,<meta name="viewport" content="user-scalable=no">

 

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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<!DOCTYPE html>
<html>
  <head>
    <style type="text/css">
      #level0 {
        /* width: 500px;
        height: 500px; */
      }
 
      #level1-0 {
        background: red;
        width: 500px;
        height: 500px;
      }
 
      #level1-1 {
        background: green;
        width: 500px;
        height: 500px;
      }
    </style>
    <meta name="viewport" content="user-scalable=no">
 
  </head>
   
  <body>
    <div id="level0">
      <div id="level1-0">
      </div>
      <div id="level1-1">
      </div>
    </div>
  </body>
  <script type="text/javascript">
 
    var level10 = document.getElementById("level1-0");
 
    level10.addEventListener('touchstart', function(e) {
        // e.preventDefault();
      console.log('touchstart',new Date().getSeconds(),new Date().getMilliseconds());
    });
 
    level10.addEventListener('touchmove', function(e) {
      console.log('touchmove',new Date().getSeconds(),new Date().getMilliseconds());
    });
 
    level10.addEventListener('touchend', function(e) {
      console.log('touchend',new Date().getSeconds(),new Date().getMilliseconds());
    });
 
    level10.onclick = function() {
      console.log('level10.onclick',new Date().getSeconds(),new Date().getMilliseconds());
    }
 
    document.body.onclick = function() {
      console.log('document.body.onclick',new Date().getSeconds(),new Date().getMilliseconds());
    }
 
    var level11 = document.getElementById("level1-1");
 
 
// level10.addEventListener('touchstart', function(e) {
//   level10.style.display = 'none';
// });
 
// level11.onclick = function() {
//   console.log('level11莫名被点击了');
// }
 
  </script>
</html>

  

posted on   码农-编程小子  阅读(742)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 单元测试从入门到精通
· 上周热点回顾(3.3-3.9)
· winform 绘制太阳,地球,月球 运作规律
< 2025年3月 >
23 24 25 26 27 28 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 1 2 3 4 5

点击右上角即可分享
微信分享提示