-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
173 lines (146 loc) · 5.26 KB
/
index.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Comic Character</title>
<meta name="viewport" content="user-scalable=no, width=device-width, initial-scale=1, maximum-scale=1">
<link href="assets/animate.css" rel="stylesheet"/>
<script src="js/shake.js"></script>
<script src="js/hammer.min.js"></script>
<style>
body {
text-align: center;
margin: auto;
display: flex;
font-family: Calibri, sans-serif;
font-size: 2em;
background-color: #dedede;
height: 100vh;
margin: 0;
}
#home {
flex: 1;
border-radius: 4px;
background: #22c1c3; /* fallback for old browsers */
background: -webkit-linear-gradient(to right, #fdbb2d, #22c1c3); /* Chrome 10-25, Safari 5.1-6 */
background: linear-gradient(to right, #fdbb2d, #22c1c3); /* W3C, IE 10+/ Edge, Firefox 16+, Chrome 26+, Opera 12+, Safari 7+ */
box-shadow: 2px 2px 14px 4px #555;
}
#home h1 {
font-size: 2em;
}
#screen {
display: none;
flex: 1;
}
#msg {
}
.person-img {
position: relative;
-webkit-animation: mymove 3s; /* Safari 4.0 - 8.0 */
-webkit-animation-iteration-count: 3; /* Safari 4.0 - 8.0 */
animation: mymove 1s;
animation-iteration-count: 3;
}
@-webkit-keyframes mymove {
from {top: 0px;}
to {top: -20px;}
}
@keyframes mymove {
from {top: 0px;}
to {top: -20px;}
}
</style>
</head>
<body>
<div id="home" class="animated pulse">
<h1>
Comic Jump
</h1>
<p>Swipe left to start game</p>
</div>
<div id="screen">
<h2>Start to jump</h2>
<p id="msg">
Total jump(s): <span id="msg-count"></span>
</p>
<p id="jump-complete">
</p>
<div id="me">
</div>
<img id="person-img" height="250" width="200" src="assets/person1.svg" alt="person"/>
</div>
</body>
<script>
var myElement = document.getElementById('home');
var hammertime = new Hammer(myElement);
hammertime.on('panleft', function (ev) {
document.getElementById("home").className = "animated fadeOutLeft";
setTimeout(animate2Screen, 200);
});
var playScreen = document.getElementById('screen');
var hammertime2 = new Hammer(playScreen);
hammertime2.on('panright', function (ev) {
document.getElementById("screen").className = "animated fadeOutRight";
setTimeout(animate1Screen, 200);
});
var animate2Screen = function () {
document.getElementById('home').style.display = "none";
document.getElementById('screen').style.display = "block";
document.getElementById('screen').className = "animated fadeInRight";
setTimeout(animatePersonImage, 400);
}
var animate1Screen = function () {
document.getElementById('screen').style.display = "none";
document.getElementById('home').style.display = "block";
document.getElementById('home').className = "animated fadeInLeft";
}
var animatePersonImage = function () {
document.getElementById('person-img').className = "animated pulse";
}
var totalShake = 0, resetCounter = 0;
var shakeEvent = new Shake({threshold: 15});
shakeEvent.start();
window.addEventListener('shake', function () {
totalShake++;
resetCounter++;
if(resetCounter === 25){
document.getElementById('person-img').className = "animated shake";
document.getElementById('jump-complete').innerText = "You jumped " + totalShake.toString();
bounceImg(3);
vibratePhone(500);
resetCounter = 0;
}else{
document.getElementById('jump-complete').innerText="";
}
document.getElementById("msg-count").innerText = totalShake.toString();
}, false);
var vibratePhone = function(time){
if ("vibrate" in navigator) {
navigator.vibrate = navigator.vibrate || navigator.webkitVibrate || navigator.mozVibrate || navigator.msVibrate;
if (navigator.vibrate) {
navigator.vibrate(time);
}
}
}
var bounceImg = function (counter) {
document.getElementById('person-img').className = "person-img";
setTimeout(function(){
document.getElementById('person-img').className = "";
}, 2800);
}
//stop listening
function stopShake() {
shakeEvent.stop();
}
if (!("ondevicemotion" in window)) {
alert("Not Supported");
}
//orientation part
var supportsOrientationChange = "onorientationchange" in window,
orientationEvent = supportsOrientationChange ? "orientationchange" : "resize";
window.addEventListener(orientationEvent, function () {
document.getElementById("orientation").innerText = ('MODE: ' + window.orientation + " width: " + screen.width);
}, false);
</script>
</html>