-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathTouchTest.html
116 lines (94 loc) · 2.69 KB
/
TouchTest.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
<!DOCTYPE html>
<html>
<head>
<title>Touch Tracker Marker</title>
<meta name="viewport" content="width=device-width, user-scalable=no">
<style type="text/css">
body { margin: 0px; overflow: hidden; }
canvas { border: 1px solid black; }
</style>
<script type="text/javascript">
var canvas;
var ctx;
var w = 0;
var h = 0;
var timer;
var updateStarted = false;
var touches = [];
function update() {
if (updateStarted)
return;
updateStarted = true;
var nw = window.innerWidth;
var nh = window.innerHeight;
if ((w != nw) || (h != nh)) {
w = nw;
h = nh;
canvas.style.width = w + 'px';
canvas.style.height = h + 'px';
canvas.width = w;
canvas.height = h;
}
ctx.clearRect(0, 0, w, h);
var i, len = touches.length;
for (i = 0; i < len; i++) {
var touch = touches[i];
var px = touch.pageX;
var py = touch.pageY;
ctx.beginPath();
ctx.arc(px, py, 20, 0, 2 * Math.PI, true);
ctx.fillStyle = "rgba(0, 0, 200, 0.2)";
ctx.fill();
ctx.lineWidth = 2.0;
ctx.strokeStyle = "rgba(0, 0, 200, 0.8)";
ctx.stroke();
console.log('drawn circle at ' + px + ',' + py);
}
updateStarted = false;
}
function ol() {
canvas = document.getElementById('canvas');
ctx = canvas.getContext('2d');
timer = setInterval(update, 15);
canvas.addEventListener('mousedown', function (ev) {
//alert(ev);
event.preventDefault();
touches = [event];
});
canvas.addEventListener('mousemove', function (ev) {
if (touches.length > 0) {
event.preventDefault();
touches = [event];
}
});
canvas.addEventListener('mouseup', function () {
ctx.clearRect(0, 0, w, h);
touches = [];
});
canvas.addEventListener('touchend', function () {
ctx.clearRect(0, 0, w, h);
touches = [];
});
canvas.addEventListener('touchmove', function (event) {
event.preventDefault();
touches = event.touches;
});
canvas.addEventListener('touchstart', function (event) {
console.log('start');
});
}
;
</script>
</head>
<body onload="ol()">
<canvas id="canvas" width="300" height="300" style="top:0px; left:0px; width: 300px; height: 300px;"></canvas>
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-58988873-1', 'auto');
ga('send', 'pageview');
</script>
</body>
</html>