-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtouchOverlay.js
More file actions
56 lines (47 loc) · 1.45 KB
/
Copy pathtouchOverlay.js
File metadata and controls
56 lines (47 loc) · 1.45 KB
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
/*jslint browser: true, devel: true */
// Variables
var el;
// Event Handlers
function touchhandler(e) {
"use strict";
event.preventDefault();
var ctx = el.getContext("2d");
ctx.fillStyle = "rgba(0, 0, 200, 0.2)";
ctx.strokeStyle = "#33B5E5";
ctx.setLineWidth(1);
ctx.beginPath();
for (var i = 0; i < e.changedTouches.length; i++) {
var x = e.changedTouches[i].pageX,
y = e.changedTouches[i].pageY;
// Touch Point
ctx.arc(x, y, 30, 0, Math.PI*2, true);
// Cross-hairs
ctx.moveTo(x, 0);
ctx.lineTo(x, y - 30);
ctx.moveTo(x, y + 30);
ctx.lineTo(x, window.innerHeight);
ctx.moveTo(0, y);
ctx.lineTo(x - 30, y);
ctx.moveTo(x + 30, y);
ctx.lineTo(window.innerWidth, y);
}
ctx.closePath();
ctx.clearRect(0, 0, window.innerWidth, window.innerHeight);
ctx.stroke();
ctx.fill();
}
function resizeCanvas(e) {
"use strict";
el.width = window.innerWidth;
el.height = window.innerHeight;
}
// Register Event Handlers
document.body.onload = function () {
"use strict";
el = document.getElementsByTagName('canvas')[0];
el.addEventListener('touchstart', touchhandler, false);
el.addEventListener('touchmove', touchhandler, false);
el.addEventListener('touchend', touchhandler, false);
window.addEventListener('resize', resizeCanvas, false);
resizeCanvas();
};