Permalink
Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
57 lines (51 sloc) 1.82 KB
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Touch Events</title>
<meta name="viewport" content="width=device-width,initial-scale=1.0,user-scalable=no">
<link rel="stylesheet" href="../include/style.css">
</head>
<body>
<header>
Example from <a href="http://amzn.com/1430236655?tag=html5anim-20"><em>Foundation HTML5 Animation with JavaScript</em></a>
</header>
<canvas id="canvas" width="400" height="400"></canvas>
<textarea id="log"></textarea>
<aside>Press and move touch inside and outside of circle (touch-capable device required).</aside>
<script src="../include/utils.js"></script>
<script src="./classes/ball.js"></script>
<script>
window.onload = function () {
var canvas = document.getElementById('canvas'),
context = canvas.getContext('2d'),
touch = utils.captureTouch(canvas),
log = document.getElementById('log'),
ball = new Ball();
ball.x = canvas.width / 2;
ball.y = canvas.height / 2;
ball.draw(context);
canvas.addEventListener('touchstart', function (event) {
event.preventDefault();
if (utils.containsPoint(ball.getBounds(), touch.x, touch.y)) {
log.value = "in ball: touchstart";
} else {
log.value = "canvas: touchstart";
}
}, false);
canvas.addEventListener('touchend', function (event) {
event.preventDefault();
log.value = "canvas: touchend";
}, false);
canvas.addEventListener('touchmove', function (event) {
event.preventDefault();
if (utils.containsPoint(ball.getBounds(), touch.x, touch.y)) {
log.value = "in ball: touchmove";
} else {
log.value = "canvas: touchmove";
}
}, false);
};
</script>
</body>
</html>