Skip to content

Instantly share code, notes, and snippets.

@frogcat
Created June 23, 2018 07:06
Show Gist options
  • Save frogcat/740a5407d5f3db2cc7079f4d03170c61 to your computer and use it in GitHub Desktop.
Save frogcat/740a5407d5f3db2cc7079f4d03170c61 to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0" />
<title>touch me</title>
</head>
<body>
<div style="position:absolute;top:0;left:0;right:0;bottom:0">
<canvas width="100%" height="100%" id="canvas"></canvas>
</div>
<script>
var canvas = document.getElementById("canvas");
canvas.width = window.innerWidth;
canvas.height = window.innerHeight;
var context = canvas.getContext("2d");
var update = function(e) {
console.log(e);
context.clearRect(0, 0, canvas.width, canvas.height);
var len = e.touches.length;
for (var i = 0; i < len; i++) {
var p = e.touches.item(i);
for (var j = i + 1; j < len; j++) {
var q = e.touches.item(j);
context.beginPath();
context.moveTo(p.clientX, p.clientY);
context.lineTo(q.clientX, q.clientY);
context.stroke();
}
}
};
canvas.addEventListener("touchstart", update);
canvas.addEventListener("touchmove", update);
canvas.addEventListener("touchend", update);
console.log(canvas.width, canvas.height);
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment