-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
93 lines (83 loc) · 2.48 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Workers test</title>
</head>
<body>
<div>
<h3>Workers</h3>
<div id="flex">
<button id="btn">Canvas</button>
<button id="fbn">Arr Ops</button>
<div class="animate" id="check">Did MT Block?</div>
</div>
<br />
<canvas width="500" height="500" id="canvas">Your browser does not support canvas =(</canvas>
</div>
<script>
const canvasBtn = document.getElementById("btn");
canvasBtn.onclick = () => {
const canvas = document.getElementById("canvas");
const offscreen = canvas.transferControlToOffscreen();
const worker = new Worker("offscreencanvas.js");;
worker.postMessage({canvas: offscreen}, [offscreen]);
}
</script>
<script>
const fibButton = document.getElementById("fbn");
fibButton.onclick = async (e) => {
const start = Date.now();
const worker = new Worker("worker.js");
const arr = new Uint16Array(300000000);
worker.postMessage(arr, [arr.buffer]);
worker.onmessage = function(e) {
const end = Date.now();
const diff = start - end;
console.log(`Transfer completed in ${diff}ms`);
}
}
</script>
<script>
const checkBox = document.getElementById("check")
const cycler = () => setTimeout(() => {
checkBox.classList.add("secondary");
setTimeout(() => {
checkBox.classList.remove("secondary");
cycler();
}, 1000);
}, 1000);
cycler();
</script>
<style>
#flex {
display: flex;
flex-direction: row;
}
#btn {
width: 100px;
height: 25px;
margin-right: 5px;
}
.animate {
animation: move 5s infinite;
}
.animate.secondary {
background: grey;
}
@keyframes move {
0% {
transform: translate(100px, 0);
}
50% {
transform: translate(0, 0);
}
100% {
transform: translate(100px, 0);
}
}
</style>
</body>
</html>