1234567891011121314151617181920212223242526272829303132333435363738394041424344 |
- <!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: 200px;
- background: #00f;
- }
- </style>
- </head>
- <body>
- <!--
- touchstart:手指触摸到一个 DOM 元素时触发。
- touchmove:手指在一个 DOM 元素上滑动时触发。
- touchend:手指从一个 DOM 元素上移开时触发。
- 每个触摸事件都包括了三个触摸列表,每个列表里包含了对应的一系列触摸点(用来实现多点触控)
- touches:当前位于屏幕上的所有手指的列表。
- targetTouches:位于当前DOM元素上手指的列表。
- changedTouches:涉及当前事件手指的列表
- -->
- <div id="box"></div>
- <script>
- var box = document.getElementById("box");
- // box.onclick = function() {
- // console.log('点击')
- // }
- box.ontouchstart = function(event) {
- console.log(event,'触发')
- }
- box.ontouchmove = function() {
- console.log("滑动")
- }
- box.ontouchend = function() {
- console.log("离开")
- }
- // click 事件 有300ms的延迟
- </script>
- </body>
- </html>
|