Debian Codegraph @

fixtures/touch.html

raw
1 <html>
2 <style>
3 body {
4 width: 200px;
5 height: 200px;
6 margin: 0;
7 }
8 button {
9 margin: 20px;
10 }
11 </style>
12
13 <body>
14 <button id="btn">touch</button>
15 </body>
16
17 <script>
18 window.touchTrack = ''
19 const body = document.body
20 body.ontouchstart = (e) => {
21 const t = e.touches[0]
22 window.touchTrack += ' start ' + (t.clientX | 0) + ' ' + (t.clientY | 0)
23 }
24 body.ontouchmove = (e) => {
25 const t = e.touches[0]
26 window.touchTrack += ' move ' + (t.clientX | 0) + ' ' + (t.clientY | 0)
27 }
28 body.ontouchend = () => {
29 window.touchTrack += ' end'
30 }
31 body.ontouchcancel = () => {
32 window.touchTrack += ' cancel'
33 }
34
35 const btn = document.getElementById('btn')
36 let start = false
37 btn.ontouchstart = () => {
38 start = true
39 }
40 btn.ontouchend = () => {
41 if (start) {
42 btn.setAttribute('tapped', true)
43 }
44 start = false
45 }
46 </script>
47 </html>