-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
141 lines (126 loc) · 3.49 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Web Worker Demo</title>
<script src="index.js" async></script>
<style type="text/css">
.center {
display: block;
margin: 0 auto;
max-width: max-content;
}
#explanation {
max-width: 400px;
margin-bottom: 40px;
}
form {
margin-top: 25px;
margin-bottom: 25px;
}
input[type="url"] {
display: block;
padding: 5px;
width: 320px;
}
form * {
margin-top: 5px;
}
.color {
width: 80px;
height: 80px;
display: inline-block;
}
#image-link {
display: none;
}
img {
max-width: 90vw;
max-height: 500px;
margin-top: 25px;
}
#loader-wrapper {
display: none;
}
#loader {
width: 50px;
height: 50px;
border: 3px solid #d3d3d3;
border-radius: 50%;
border-top-color: green;
animation: spin 1s ease-in-out infinite;
-webkit-animation: spin 1s ease-in-out infinite;
}
@keyframes spin {
to {
-webkit-transform: rotate(360deg);
}
}
@-webkit-keyframes spin {
to {
-webkit-transform: rotate(360deg);
}
}
#error-message {
display: none;
background-color: #f5e4e4;
color: #b22222;
border-radius: 5px;
margin-top: 10px;
padding: 10px;
}
</style>
</head>
<body>
<div class="center">
<h1>Web Worker Demo</h1>
<div id="explanation">
<p>
This demo shows how
<a
href="https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API"
>Web Workers</a
>
can be used to make websites more responsive by offloading
CPU-intensive work from the
<a
href="https://developer.mozilla.org/en-US/docs/Glossary/Main_thread"
>main thread</a
>. The source code is available on
<a href="https://github.com/dguo/web-worker-demo">GitHub</a>.
</p>
<p>
Try generating a color palette from a given image both with and
without a worker. Notice that without a worker, the time freezes
during the processing, and you can no longer interact with the form.
</p>
</div>
<p>The current time is: <span id="time"></span></p>
<form id="image-url-form">
<label for="image-url">Direct image URL</label>
<input
type="url"
name="url"
value="https://upload.wikimedia.org/wikipedia/commons/1/1f/Grapsus_grapsus_Galapagos_Islands.jpg"
/>
<input type="checkbox" name="worker" />
<label for="worker"> Use worker</label><br />
<input type="submit" value="Generate Color Palette" />
<p id="error-message"></p>
</form>
</div>
<div id="loader-wrapper" class="center">
<div id="loader"></div>
</div>
<div id="colors-wrapper" class="center">
<div id="color-0" class="color"></div>
<div id="color-1" class="color"></div>
<div id="color-2" class="color"></div>
<div id="color-3" class="color"></div>
</div>
<a class="center" id="image-link" target="_blank">
<img id="image" crossorigin="anonymous" />
</a>
</body>
</html>