-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmultipletouch.html
More file actions
53 lines (45 loc) · 1.55 KB
/
multipletouch.html
File metadata and controls
53 lines (45 loc) · 1.55 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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<meta name="viewport" content="width=device-width,initial-scale=1.0,user-scalable=no">
<style media="screen">
.box {width:200px; height:200px;background:#CCC;position:absolute;left:0;top:0;}
</style>
<script>
function touchDrag(oBox){
var oS=document.getElementById('s1');
oBox.addEventListener('touchstart', function (ev){
var disX=ev.targetTouches[0].pageX-oBox.offsetLeft;
var disY=ev.targetTouches[0].pageY-oBox.offsetTop;
function fnMove(ev){
oS.innerHTML=ev.targetTouches.length;
oBox.style.left=ev.targetTouches[0].pageX-disX+'px';
oBox.style.top=ev.targetTouches[0].pageY-disY+'px';
ev.preventDefault();
}
function fnEnd(){
oBox.removeEventListener('touchmove', fnMove, false);
oBox.removeEventListener('touchend', fnEnd, false);
}
oBox.addEventListener('touchmove', fnMove, false);
oBox.addEventListener('touchend', fnEnd, false);
ev.preventDefault();
}, false);
}
window.onload=function (){
var aBox=document.getElementsByTagName('div');
for(var i=0;i<aBox.length;i++){
touchDrag(aBox[i]);
}
};
</script>
</head>
<body>
<span id="s1"></span>
<div class="box" style="background:#FA0;"></div>
<div class="box" style="background:#0FA; left:200px; top:50px;"></div>
<div class="box" style="background:#A0F; left:100px; top:150px;"></div>
</body>
</html>