-
Notifications
You must be signed in to change notification settings - Fork 0
/
bingo.html
92 lines (82 loc) · 3.03 KB
/
bingo.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
<!DOCTYPE html>
<!--suppress ALL -->
<html lang="en">
<style type="text/css">
@keyframes grow {
from {
transform: scale(1);
}
50% {
transform: scale(2);
}
to {
transform: scale(1);
}
}
.grow-animation {
animation: grow 1s linear 0.1s;
}
</style>
<head>
<title>Bootstrap Example</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
<body>
<div class="jumbotron text-center">
<h1 style="font-size: 150px;" id="ultimo-numero" class="grow-animation"></h1>
</div>
<div class="container">
<div class="row">
<div class="col-sm-12">
<h2 class='text-center' id="numeros"></h2>
</div>
</div>
</div>
<script>
/*global $*/
$(document).ready(function () {
let lastNum = -1;
setInterval(function () {
$.ajax({
url: window.location.origin + '/numeros',
success: function (data) {
data = JSON.parse(data);
if (data.length) {
$("#ultimo-numero").text(data[data.length - 1]);
let numeros = data[0];
for (let i = 1; i < data.length; i++)
numeros += ' - ' + data[i];
$("#numeros").text(numeros);
if (lastNum !== data[data.length - 1]) {
lastNum = data[data.length - 1];
try {
const element = $("#ultimo-numero")[0];
// -> removing the class
element.classList.remove("grow-animation");
// -> triggering reflow /* The actual magic */
// without this it wouldn't work. Try uncommenting the line and the transition won't be retriggered.
// Oops! This won't work in strict mode. Thanks Felis Phasma!
// element.offsetWidth = element.offsetWidth;
// Do this instead:
void element.offsetWidth;
// -> and re-adding the class
element.classList.add("grow-animation");
} catch (e) {
console.log(e);
}
}
} else {
$("#ultimo-numero").text('');
$("#numeros").text('')
}
}
});
}, 500);
});
</script>
</body>
</html>