xdshi
  <!DOCTYPE html>
  <html lang="en">
  <head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
  <title>Document</title>
  <style>
  div{
  width: 200px;
  height: 200px;
  background-color: red;
  }
  </style>
  </head>
  <body>
  <!-- 移动端有特殊的触摸事件只有移动端有 必须要使用模拟器调试才能触发 -->
  <div></div>
  <script>
  // 1. 有3个touch事件
  // 1. touchstart
  // 2. touchmove
  // 3. touchend
  // 和鼠标的mousemove mouseleave mouseover 有点相似
  var div = document.querySelector(\'div\');
  //手指触摸开始的时候触发的事件
  div.addEventListener(\'touchstart\', function () {
  console.log(\'touchstart\');
  });
  //手指在屏幕上移动的时候触发的事件
  div.addEventListener(\'touchmove\', function () {
  console.log(\'touchmove\');
  });
  //手指触摸结束 的时候触发的事件
  div.addEventListener(\'touchend\', function () {
  console.log(\'touchend\');
  });
   
  </script>
  </body>
 
  • </html>

分类:

技术点:

相关文章:

  • 2021-09-02
  • 2021-10-01
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-01-29
  • 2022-02-16
猜你喜欢
  • 2021-12-09
  • 2021-07-10
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案