-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmagic_touch.html
87 lines (73 loc) · 3.3 KB
/
magic_touch.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
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width,user-scalable=no">
<meta name="description" content="Canvas 2D Context API Primer">
<meta name="keywords" content="HTML,JavaScript">
<meta name="author" content="Raul Roa">
<title>Touch Events</title>
<style type="text/css">
canvas { border: 1px solid black; }
textarea { width: 600px; height: 200px; display: block; }
</style>
<script>
window.onload = function () {
// Get the canvas element
//
var canvas = document.getElementById('canvas');
// Get a reference to the drawing context
//
var ctx = canvas.getContext('2d');
var width = 0;
var height = 0;
var timer;
var updateStarted = false;
var touches = [];
if( canvas && ctx ){
// Set the timer
//
timer = setInterval(update, 16);
canvas.addEventListener("touchmove", function(event) {
event.preventDefault();
touches = event.touches;
}, false);
canvas.addEventListener("touchend", function(event) {
// Clear the canvas
//
ctx.clearRect(0, 0, canvas.width, canvas.height);
}, false);
}
function update() {
if (updateStarted) return;
updateStarted = true;
// Clear the canvas
//
ctx.clearRect(0, 0, canvas.width, canvas.height);
for (var index = 0; index < touches.length; ++index) {
var touch = touches[index];
var px = touch.pageX;
var py = touch.pageY;
ctx.beginPath();
ctx.arc(px, py, 20, 0, 2 * Math.PI, true);
ctx.fillStyle = "rgba(200, 0, 200, 0.2)";
ctx.fill();
ctx.lineWidth = 2.0;
ctx.strokeStyle = "rgba(200, 0, 200, 0.8)";
ctx.stroke();
ctx.closePath();
}
updateStarted = false;
}
};
</script>
</head>
<body>
<p>
<a href="index.html">Back to index</a>
</p>
<canvas id="canvas" width="300" height="300" tabindex='0' class="default">
This browser or document mode doesn't support canvas
</canvas>
</body>
</html>