-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathimage.html
78 lines (67 loc) · 2.28 KB
/
image.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
<title>image</title>
<style>
body {
margin: 0;
padding: 0;
}
#image {
opacity: 0;
transition: opacity 1s;
max-width: 100%;
max-height: 100vh;
position: absolute;
top: 50%;
left: 50%;
margin-right: -50%;
transform: translate(-50%, -50%);
}
#image.show {
opacity: 1;
}
</style>
</head>
<body>
<img id="image" src="data:image/gif;base64,R0lGODlhAQABAAD/ACwAAAAAAQABAAACADs=" alt="image" />
<script src="https://cdn.socket.io/4.7.5/socket.io.min.js" integrity="sha384-2huaZvOR9iDzHqslqwpR87isEmrfxqyWOF7hr7BY6KG0+hVKLoEXMPUJw3ynWuhO" crossorigin="anonymous"></script>
<script>
const socket = io();
const img = document.getElementById("image");
let interval;
let queue = [];
let running = false;
socket.on("connect", yes => {
if (socket.connected) socket.emit("got the stuff?", stuff => (interval = stuff.seconds));
});
socket.on("new", url => {
queue.push(url);
let preloadImg = new Image();
preloadImg.onload = () => {
if (!running) run();
};
preloadImg.src = url;
});
function run() {
running = true;
const url = queue.shift();
img.src = url;
img.classList.toggle("show");
setTimeout(() => {
img.classList.toggle("show");
if (queue.length == 0) {
running = false;
return;
}
setTimeout(() => {
run();
}, 1000);
}, 1000 * interval);
}
</script>
</body>
</html>