-
Notifications
You must be signed in to change notification settings - Fork 0
/
example.htm
115 lines (102 loc) · 2.53 KB
/
example.htm
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
<meta http-equiv="Content-Security-Policy" content="default-src * data:; style-src * 'unsafe-inline'; script-src * 'unsafe-inline' 'unsafe-eval'">
<title>Gestures</title>
<style type="text/css">
*{
padding: 0px;
margin: 0px;
touch-action: none;
font-size: 12px;
font-family: arial;
user-select: none;
}
.testholder{
position: relative;
margin-top: 20px;
margin-left: 5%;
width: 90%;
height: 350px;
overflow: hidden;
border: 3px solid red;
border-radius: 5px;
}
#testsubject{
cursor: pointer;
position: absolute;
width: 80px;
height: 40px;
border: 2px solid blue;
text-align: center;
line-height: 18px;
}
</style>
<script src="Gestures.js"></script>
<script>
var output, divX = 20, divY = 20, lastPageX, lastPageY, moving = false;
function startHolding(e){
lastPageX = e.x;
lastPageY = e.y;
moving = true;
e.elm.style.opacity = 0.5;
}
function stopHolding(e){
moving = false;
e.elm.style.opacity = 1;
}
function handleMove(e){
if(!moving){
return;
}
divX += e.x - lastPageX;
divY += e.y - lastPageY;
e.elm.style.left = divX + "px";
e.elm.style.top = divY + "px";
lastPageX = e.x;
lastPageY = e.y;
}
function onevent(e){
let newDiv = document.createElement("div");
let text = JSON.stringify(e);
let i, list = Object.getOwnPropertyNames(Gestures.Types);
for(i=0; i<list.length; i++){
if(Gestures.Types[list[i]] == e.type){
text = list[i] + text;
break;
}
}
newDiv.innerText = text;
output.insertBefore(newDiv, output.firstChild);
if(e.type == Gestures.Types.Holding){
startHolding(e);
}
else if(e.type == Gestures.Types.Up){
stopHolding(e);
}
else if(e.type == Gestures.Types.Move){
handleMove(e);
}
}
function onload(){
let subject = document.getElementById("testsubject");
subject.style.left = divX + "px";
subject.style.top = divY + "px";
Gestures.addListener(subject, onevent);
output = document.getElementById("output");
}
window.addEventListener("load", onload, false);
</script>
</head>
<body>
<h1>Gestures</h1>
<div>Tap, swipe and hold the test subject. Hold first to move.</div>
<div class="testholder">
<div id="testsubject">Test<br/>Subject</div>
</div>
<h3>Output</h3>
<div id="output"></div>
</body>
</html>