9_移动端事件.html 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  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: 100px;
  10. height: 100px;
  11. background-color: pink;
  12. }
  13. </style>
  14. </head>
  15. <body>
  16. <div class="box"></div>
  17. <script>
  18. var oBox = document.querySelector(".box");
  19. // 鼠标点击事件
  20. // 鼠标点击会有一个300毫秒的延迟
  21. oBox.onclick = function(){
  22. console.log("点击事件");
  23. }
  24. // 移动端点击事件
  25. // 移动端点击事件不会有延迟
  26. oBox.ontouchstart = function(){
  27. console.log("移动端点击start事件");
  28. }
  29. // 移动端点击事件会有一个
  30. oBox.ontouchend = function(){
  31. console.log("移动端点击end事件");
  32. }
  33. // touchmove 移动端滑动事件
  34. oBox.ontouchmove = function(){
  35. console.log("移动端滑动事件");
  36. }
  37. </script>
  38. </body>
  39. </html>