-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.html
288 lines (250 loc) · 8.78 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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width; initial-scale=1.0;" />
<title>Web Cards Against Humanity</title>
<style>
html {
font-family: "Helvetica Neue";
}
body {
display: grid;
grid-template-columns: repeat(2, 1fr);
grid-template-rows: 1fr 2fr 1fr;
align-content: center;
justify-content: center;
align-items: center;
height: 100vh;
background-color: #fdfdfd;
margin: 0;
padding: 0;
grid-auto-flow: row;
}
header,
footer {
grid-column: 1 / 3;
justify-self: center;
}
.card {
display: grid;
border-radius: 10px;
grid-row: 2/3;
height: 70vh;
grid-template-rows: repeat(3, 1fr) 200px;
box-shadow: 0 6px 6px grey;
width: 75%;
justify-self: center;
justify-items: start;
align-items: center;
}
.card h2 {
padding-top: 30px;
font-size: 48px;
}
.card h4 {
grid-row-start: 4;
font-size: 18px;
grid-column-start: 1;
padding-left: 90px;
}
.card h2,
h4 {
padding-left: 50px;
padding-right: 100px;
}
.card svg {
padding-left: 50px;
grid-row-start: 4;
grid-column-start: 1;
}
#card-1 {
background-color: #222;
color: white;
}
#card-2 {
background-color: #fff;
color: #222;
}
#card-2:hover {
background-color: #eee;
transition: background-color .3s ease-out;
cursor: pointer;
}
#card-1:hover {
background-color: #000;
transition: background-color .3s ease-out;
cursor: pointer;
}
.moveCard {
animation: card-animation .7s ease;
}
@keyframes card-animation {
from {
transform: translateY(100px);
opacity: 0;
}
to {
transform: translateY(0px);
opacity: 100%;
}
}
button {
grid-column: 1/3;
font-weight: bold;
width: 15%;
background-color: white;
outline: none;
justify-self: center;
border-radius: 7px;
padding: 10px;
font-size: 18px;
border: 2px solid black;
cursor: pointer;
box-shadow: inset 0 -3px 0 0 #232323;
}
button:active {
box-shadow: 0 0 0;
color: black;
transform: translate(0px, 2px)
}
@media only screen and (max-device-width: 420px) {
body {
grid-template-columns: 1fr;
grid-template-rows: repeat(4, 1fr);
grid-template-areas: "header" "card1" "card2" "footer";
justify-items: start;
align-items: center;
-webkit-text-size-adjust: none;
grid-row-gap: 10px;
}
header {
grid-area: header;
font-size: 14px;
text-align: center;
}
#card-1 {
grid-area: card1;
}
#card-2 {
grid-area: card2;
}
.card {
width: 95%;
height: 35vh;
grid-template-columns: 1fr;
grid-template-rows: 1fr;
justify-items: center;
}
.card h2 {
font-size: 24px;
padding: 0 50px;
}
.card h4,
svg {
display: none;
}
button {
display: none;
}
}
</style>
<link rel="stylesheet" type="text/css" href="https://necolas.github.io/normalize.css/7.0.0/normalize.css">
</head>
<body>
<header>
<h1>Web Cards Against Humanity</h1>
</header>
<div id="card-1" class="card">
<h2 id="blackCardText">Cards Against Humanity</h2>
<svg fill="#FFFFFF" width="30pt" height="30pt" version="1.1" viewBox="0 0 100 100" xmlns="http://www.w3.org/2000/svg">
<g>
<path d="m33.602 60.012v-28.938l-1.1445-1.9805c-0.59375-1.0273-1.6719-1.6016-2.7773-1.6016-0.54297 0-1.0938 0.13672-1.5977 0.42969l-21.48 12.402c-1.5273 0.88281-2.0547 2.8477-1.1719 4.375l16.715 28.945c0.88281 1.5273 2.8438 2.0547 4.375 1.1719l18.055-10.426h-6.5859c-2.418 0.003906-4.3867-1.9609-4.3867-4.3789z"/>
<path d="m93.102 40.375l-22.375-10.711c-1.5938-0.76172-3.5078-0.085937-4.2734 1.5078l-14.43 30.148c-0.082032 0.17188-0.14453 0.35156-0.19531 0.53125-0.019531 0.066407-0.03125 0.13672-0.046875 0.20313-0.023438 0.10937-0.039062 0.22266-0.050781 0.33594-0.007813 0.085937-0.015625 0.17188-0.015625 0.25781 0 0.097656 0.007812 0.19141 0.011718 0.28516 0.007813 0.09375 0.007813 0.18359 0.023438 0.27734 0.03125 0.1875 0.074219 0.37109 0.13672 0.55469 0.28516 0.80859 0.86719 1.4531 1.6367 1.8242l22.375 10.711c1.5938 0.76562 3.5078 0.085938 4.2734-1.5078l14.434-30.148c0.76562-1.5898 0.089843-3.5078-1.5039-4.2695z"/>
<path d="m65.391 30.66c0.16406-0.34375 0.37109-0.65234 0.60938-0.92969v-3.1445c0-1.7656-1.4375-3.2031-3.2031-3.2031h-24.812c-1.7656 0-3.2031 1.4375-3.2031 3.2031v33.426c0 1.7656 1.4375 3.2031 3.2031 3.2031h12.574c-0.097656-0.81641 0.035156-1.6445 0.39844-2.4023z"/>
</g>
</svg>
<h4>Cards Against Humanity</h4>
</div>
<div id="card-2" class="card">
<h2 id="whiteCardText">Cards Against Humanity</h2>
<svg width="30pt" height="30pt" version="1.1" viewBox="0 0 100 100" xmlns="http://www.w3.org/2000/svg">
<g>
<path d="m33.602 60.012v-28.938l-1.1445-1.9805c-0.59375-1.0273-1.6719-1.6016-2.7773-1.6016-0.54297 0-1.0938 0.13672-1.5977 0.42969l-21.48 12.402c-1.5273 0.88281-2.0547 2.8477-1.1719 4.375l16.715 28.945c0.88281 1.5273 2.8438 2.0547 4.375 1.1719l18.055-10.426h-6.5859c-2.418 0.003906-4.3867-1.9609-4.3867-4.3789z"/>
<path d="m93.102 40.375l-22.375-10.711c-1.5938-0.76172-3.5078-0.085937-4.2734 1.5078l-14.43 30.148c-0.082032 0.17188-0.14453 0.35156-0.19531 0.53125-0.019531 0.066407-0.03125 0.13672-0.046875 0.20313-0.023438 0.10937-0.039062 0.22266-0.050781 0.33594-0.007813 0.085937-0.015625 0.17188-0.015625 0.25781 0 0.097656 0.007812 0.19141 0.011718 0.28516 0.007813 0.09375 0.007813 0.18359 0.023438 0.27734 0.03125 0.1875 0.074219 0.37109 0.13672 0.55469 0.28516 0.80859 0.86719 1.4531 1.6367 1.8242l22.375 10.711c1.5938 0.76562 3.5078 0.085938 4.2734-1.5078l14.434-30.148c0.76562-1.5898 0.089843-3.5078-1.5039-4.2695z"/>
<path d="m65.391 30.66c0.16406-0.34375 0.37109-0.65234 0.60938-0.92969v-3.1445c0-1.7656-1.4375-3.2031-3.2031-3.2031h-24.812c-1.7656 0-3.2031 1.4375-3.2031 3.2031v33.426c0 1.7656 1.4375 3.2031 3.2031 3.2031h12.574c-0.097656-0.81641 0.035156-1.6445 0.39844-2.4023z"/>
</g>
</svg>
<h4>Cards Against Humanity</h4>
</div>
<button id="cardButton">New cards</button>
<footer>
<p>
© Cards Against Humanity
</p>
</footer>
<script>
const url = 'https://raw.githubusercontent.com/crhallberg/json-against-humanity/master/dev/cah.json';
function fetchBlackCard() {
fetch(url)
.then(function(response) {
return response.json();
})
.then(function(data) {
// Do stuff with the JSON
var randomBlackCard = data.blackCards[Math.floor(Math.random() * data.blackCards.length)].text;
const setBlackCard = document.getElementById('blackCardText');
setBlackCard.innerHTML = `${randomBlackCard}`;
console.log(randomBlackCard);
// var randomWhiteCard = data.whiteCards[Math.floor(Math.random()*data.whiteCards.length)];
// console.log(randomWhiteCard);
})
.catch(function(error) {
console.log(`There's a problem`, error);
})
}
function fetchWhiteCard() {
fetch(url)
.then(function(response) {
return response.json();
})
.then(function(data) {
// Do stuff with the JSON
var randomWhiteCard = data.whiteCards[Math.floor(Math.random() * data.whiteCards.length)];
const setWhiteCard = document.getElementById('whiteCardText');
setWhiteCard.innerHTML = `${randomWhiteCard}`;
// console.log(randomWhiteCard);
})
.catch(function(error) {
console.log(`There's a problem`, error);
})
}
function animateBlackText() {
var blackText = document.getElementById('blackCardText');
blackText.classList.remove('moveCard');
void blackText.offsetWidth;
blackText.classList.add('moveCard');
}
function animateWhiteText() {
var whiteText = document.getElementById('whiteCardText');
whiteText.classList.remove('moveCard');
void whiteText.offsetWidth;
whiteText.classList.add('moveCard');
}
document.getElementById('card-1').addEventListener("click", function() {
fetchBlackCard();
animateBlackText();
});
document.getElementById('card-2').addEventListener("click", function() {
fetchWhiteCard();
animateWhiteText();
});
document.getElementById('cardButton').addEventListener("click", function() {
animateBlackText();
animateWhiteText();
fetchWhiteCard();
fetchBlackCard();
})
</script>
</body>
</html>