forked from supperjet/H5-Animation
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtouch-event.html
51 lines (44 loc) · 1.55 KB
/
touch-event.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>touch-event</title>
</head>
<body>
<canvas id="canvas" width="500" height="500" style="background:#000;
"> your browser not support canvas</canvas>
<textarea name="textarea" id="txt" cols="30" rows="10"></textarea>
<script src="../js/utils.js"></script>
<script src="../js/ball.js"></script>
<script>
window.onload = function(){
var canvas = document.getElementById('canvas'),
log = document.getElementById('txt'),
context = canvas.getContext('2d'),
touch = utils.captureTouch(canvas);
var ball = new Ball();
ball.x = canvas.width/2, ball.y = canvas.height/2;
ball.draw(context);
function state(wrd){
if(utils.containsPoint(ball.getBounds(), touch.x, touch.y)){
log.value = "in ball :" + wrd;
}else{
log.value = "in canvas :" + wrd;
}
}
canvas.addEventListener('touchstart', function(event){
event.preventDefault();
state("touchstart");
canvas.addEventListener('touchend',function(evnet){
evnet.preventDefault();
log.value = "canvas : touchend";
}, false);
canvas.addEventListener('touchmove', function(event){
event.preventDefault();
state("touchmove");
}, false);
}, false);
}
</script>
</body>
</html>