7_移动端事件.html 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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: red;
  12. position: absolute;
  13. top: 0;
  14. left: 0;
  15. }
  16. .box2{
  17. width: 200px;
  18. height: 200px;
  19. background-color: blue;
  20. position: absolute;
  21. top: 0;
  22. left: 0;
  23. }
  24. </style>
  25. </head>
  26. <body>
  27. <div class="box2"></div>
  28. <div class="box"></div>
  29. <script>
  30. let oBox = document.querySelector('.box');
  31. let oBox2 = document.querySelector('.box2');
  32. oBox.addEventListener("touchstart",function(){
  33. this.style.display = 'none';
  34. })
  35. oBox2.addEventListener("click",function(){
  36. console.log("click")
  37. })
  38. // oBox.onclick = function(){
  39. // console.log('click');
  40. // }
  41. // oBox.addEventListener("touchstart",function(){
  42. // console.log('点击');
  43. // })
  44. // oBox.addEventListener("touchmove",function(){
  45. // console.log('滑动');
  46. // })
  47. // oBox.addEventListener("touchend",function(){
  48. // console.log('离开');
  49. // })
  50. </script>
  51. </body>
  52. </html>