forked from GianlucaGuarini/Tocca.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdemo-fun.html
executable file
·184 lines (179 loc) · 4.17 KB
/
demo-fun.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
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
<html>
<head>
<title>Tocca.js</title>
<link href='http://fonts.googleapis.com/css?family=Sansita+One' rel='stylesheet' type='text/css'>
<style>
body {
font-family: 'Sansita One', cursive;
color:#aaa;
background:radial-gradient(#002D59, #1B2836);
background-size: cover;
background-repeat: no-repeat;
height: 100%;
overflow: hidden;
}
a {
color:yellow;
text-decoration: none;
}
::selection { background: transparent; }
dl dd {
color:green;
}
b {
color:yellow;
margin-left:3px;
}
#wrapper {
position:absolute;
left:50%;
top:50%;
margin-top:-200px;
margin-left:-200px;
width:400px;
height:400px;
color:white;
cursor:pointer;
}
#test {
pointer-events:none;
position:absolute;
text-align: center;
font-size: 30px;
line-height: 400px;
width:400px;
height:400px;
background:rgba(0,0,0,0.5);
border-radius:30px;
}
.swipedown {
animation: movedown 0.3s ease-in-out infinite alternate;
}
.swipeup {
animation: moveup 0.3s ease-in-out infinite alternate;
}
.swipeleft {
animation: moveleft 0.3s ease-in-out infinite alternate;
}
.swiperight {
animation: moveright 0.3s ease-in-out infinite alternate;
}
.tap {
animation: pulse 0.3s ease-in-out infinite alternate;
}
.dbltap {
animation: pulse 0.15s ease-in-out infinite alternate;
}
@keyframes movedown {
0% {
transform:translateY(0px);
}
100% {
transform:translateY(20px);
}
}
@keyframes moveup {
0% {
transform:translateY(0px);
}
100% {
transform:translateY(-20px);
}
}
@keyframes moveleft {
0% {
transform:translateX(0px);
}
100% {
transform:translateX(-20px);
}
}
@keyframes moveright {
0% {
transform:translateX(0px);
}
100% {
transform:translateX(20px);
}
}
@keyframes pulse {
0% {
transform:scale(1);
}
100% {
transform:scale(0.8);
}
}
</style>
</head>
<body>
<h1><a href="https://github.com/GianlucaGuarini/Tocca.js" target="_blank">Tocca.js</a></h1>
<p>Try the following events: <b>tap</b>, <b>dbltap</b>, <b>swipeup</b>, <b>swipedown</b>, <b>swipeleft</b>, <b>swiperight</b></p>
<dl id="data">
<dt><strong>Event Name</strong></dt>
<dd id="eventName"></dd>
<dt>Event x</dt>
<dd id="currX"></dd>
<dt>Event y</dt>
<dd id="currY"></dd>
<dt>Swipe Event distance x</dt>
<dd id="distanceX"></dd>
<dt>Swipe Event distance y</dt>
<dd id="distanceY"></dd>
</dl>
<div id="wrapper"><div id="test">Touch me please!</div></div>
<script src="bind.polyfill.js"></script>
<script src="Tocca.js"></script>
<script>
var $ = document.querySelector.bind(document),
eventName = $('#eventName'),
currX = $('#currX'),
currY = $('#currY'),
distanceX = $('#distanceX'),
distanceY = $('#distanceY'),
test = $('#test'),
wrapper = $('#wrapper'),
preventDefault = function(e){e.preventDefault();},
nookie = [
'Oh yes!',
'One more time!',
'Give me more!',
'Rock and roll baby!',
'Yeah right there!',
'Turn me on..',
'♥ ♥ ♥',
'OMG you are so good!'
// shall I keep going?!
];
wrapper.addEventListener('tap',updateHtml);
wrapper.addEventListener('dbltap',updateHtml);
wrapper.addEventListener('swipeup',updateHtml);
wrapper.addEventListener('swipedown',updateHtml);
wrapper.addEventListener('swipeleft',updateHtml);
wrapper.addEventListener('swiperight',updateHtml);
wrapper.addEventListener('touchmove',preventDefault);
wrapper.addEventListener('touchstart',preventDefault);
wrapper.addEventListener('touchend',preventDefault);
wrapper.addEventListener('mousedown',preventDefault);
wrapper.addEventListener('mouseleave',preventDefault);
wrapper.addEventListener('mousemove',preventDefault);
function updateHtml (e){
eventName.innerHTML = e.type;
currX.innerHTML = e.x;
currY.innerHTML = e.y;
test.innerHTML = nookie[~~(Math.random() * nookie.length)];
distanceX.innerHTML = e.distance ? e.distance.x : 'undefined';
distanceY.innerHTML = e.distance ? e.distance.y : 'undefined';
if (/swipedown|swipeup/.test(e.type))
test.classList.add(e.type);
else
wrapper.classList.add(e.type);
setTimeout(function(){
test.className = '';
wrapper.className = '';
},600);
}
</script>
<script src="//cdnjs.cloudflare.com/ajax/libs/prefixfree/1.0.7/prefixfree.min.js"></script>
</body>
</html>