| 12345678910111213141516171819202122232425262728293031323334353637383940 |
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <title>Document</title>
- <style>
- #box{
- width: 200px;
- height: 100px;
- background-color: red;
- }
- </style>
- </head>
- <body>
- <div id="box"></div>
- <script>
- // 获取盒子
- var box = document.getElementById("box");
- // 鼠标点击事件可以在移动端使用 但是会有延迟时间 300ms 不建议在移动端使用
- box.onclick = function(){
- console.log("点击了盒子");
- }
- // 触摸开始事件 当手指触摸到盒子时 触发 没有延迟时间 建议在移动端使用移动端专属事件(只能应用于移动端)
- box.ontouchstart = function(){
- console.log("触摸开始");
- }
- // 触摸移动事件 当手指在盒子上移动时 触发 没有延迟时间 建议在移动端使用移动端专属事件(只能应用于移动端)
- box.ontouchmove = function(){
- console.log("触摸移动");
- }
- // 触摸结束事件 当手指从盒子上移开时 触发 没有延迟时间 建议在移动端使用移动端专属事件(只能应用于移动端)
- box.ontouchend = function(){
- console.log("触摸结束");
- }
-
- </script>
- </body>
- </html>
|