9.touch.html 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <title>Document</title>
  7. <style>
  8. #box {
  9. width: 200px;
  10. height: 200px;
  11. background: #00f;
  12. }
  13. </style>
  14. </head>
  15. <body>
  16. <!--
  17. touchstart:手指触摸到一个 DOM 元素时触发。
  18. touchmove:手指在一个 DOM 元素上滑动时触发。
  19. touchend:手指从一个 DOM 元素上移开时触发。
  20. 每个触摸事件都包括了三个触摸列表,每个列表里包含了对应的一系列触摸点(用来实现多点触控)
  21. touches:当前位于屏幕上的所有手指的列表。
  22. targetTouches:位于当前DOM元素上手指的列表。
  23. changedTouches:涉及当前事件手指的列表
  24. -->
  25. <div id="box"></div>
  26. <script>
  27. var box = document.getElementById("box");
  28. // box.onclick = function() {
  29. // console.log('点击')
  30. // }
  31. box.ontouchstart = function(event) {
  32. console.log(event,'触发')
  33. }
  34. box.ontouchmove = function() {
  35. console.log("滑动")
  36. }
  37. box.ontouchend = function() {
  38. console.log("离开")
  39. }
  40. // click 事件 有300ms的延迟
  41. </script>
  42. </body>
  43. </html>