-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclock.html
285 lines (253 loc) · 8.84 KB
/
clock.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
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>考场时间</title>
<!-- PWA Manifest -->
<link rel="manifest" href="manifest.json">
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
font-family: 'Poppins', sans-serif;
}
body {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
min-height: 100vh;
background: #acbaca;
}
.clock {
position: relative;
width: 300px;
height: 300px;
background: #c9d5e0;
display: flex;
justify-content: center;
align-items: center;
border-radius: 50px;
box-shadow: 30px 30px 30px -10px rgba(0, 0, 0, 0.15),
inset 15px 15px 10px rgba(255, 255, 255, 0.75),
-15px -15px 35px rgba(255, 255, 255, 0.55),
inset -1px -1px 10px rgba(0, 0, 0, 0.2);
margin-bottom: 30px; /* 增加间距 */
}
.clock::before {
content: '';
position: absolute;
width: 4px;
height: 4px;
background: #e91e63;
border-radius: 50%;
z-index: 1000;
box-shadow: 0 0 0 1px #e91e63,
0 0 0 3px #fff,
0 0 5px 5px rgba(0, 0, 0, 0.15);
}
.clock .numbers {
position: absolute;
inset: 35px;
background: #152b4a;
border-radius: 50%;
box-shadow: 5px 5px 15px #152b4a66,
inset 5px 5px 5px rgba(255, 255, 255, 0.75),
-6px -6px 10px rgba(255, 255, 255, 1);
}
.clock .numbers span {
position: absolute;
inset: 5px;
text-align: center;
color: #fff;
font-size: 1.25em;
transform: rotate(calc(90deg * var(--i)));
}
.clock .numbers span b {
font-weight: 600;
display: inline-block;
transform: rotate(calc(-90deg * var(--i)));
}
.clock .numbers::before {
content: '';
position: absolute;
inset: 35px;
background: linear-gradient(#2196f3, #e91e63);
border-radius: 50%;
animation: animate 2s linear infinite;
}
@keyframes animate {
0% {
transform: rotate(0deg);
}
100% {
transform: rotate(360deg);
}
}
.clock .numbers::after {
content: '';
position: absolute;
inset: 38px;
background: #152b4a;
border-radius: 50%;
}
.clock .numbers .circle {
position: absolute;
inset: 0;
border-radius: 50%;
display: flex;
justify-content: center;
z-index: 10;
}
.clock .numbers .circle i {
position: absolute;
width: 3px;
height: 50%;
background: #fff;
transform-origin: bottom;
transform: scaleY(0.55);
}
.clock .numbers .circle#hr i {
width: 4px;
transform: scaleY(0.3);
}
.clock .numbers .circle#mn i {
transform: scaleY(0.45);
}
.clock .numbers .circle#sc i {
width: 2px;
transform: scaleY(0.55);
background: #c91e63;
box-shadow: 0 30px 0 #e91e63;
}
/* 数字时钟样式 */
#digital-clock {
font-size: 5em; /* 放大字体 */
color: #fff;
background: #152b4a;
padding: 20px 40px;
border-radius: 10px;
box-shadow: 5px 5px 15px #152b4a66,
inset 5px 5px 5px rgba(255, 255, 255, 0.75),
-6px -6px 10px rgba(255, 255, 255, 1);
margin-bottom: 20px; /* 与按钮间距 */
}
/* 全屏按钮样式 */
#fullscreen-btn {
padding: 10px 20px;
font-size: 1em;
color: #fff;
background-color: #e91e63;
border: none;
border-radius: 5px;
cursor: pointer;
box-shadow: 3px 3px 10px rgba(0,0,0,0.2);
transition: background-color 0.3s;
}
#fullscreen-btn:hover {
background-color: #d81b60;
}
</style>
</head>
<body>
<div class="clock">
<div class="numbers">
<span style="--i:0"><b>12</b></span>
<span style="--i:1"><b>3</b></span>
<span style="--i:2"><b>6</b></span>
<span style="--i:3"><b>9</b></span>
<div class="circle" id="hr"><i></i></div>
<div class="circle" id="mn"><i></i></div>
<div class="circle" id="sc"><i></i></div>
</div>
</div>
<!-- 数字时钟容器 -->
<div id="digital-clock">00:00:00</div>
<!-- 全屏按钮 -->
<button id="fullscreen-btn">全屏/退出全屏</button>
<script>
// 模拟时钟
let hr = document.querySelector('#hr');
let mn = document.querySelector('#mn');
let sc = document.querySelector('#sc');
setInterval(() => {
let day = new Date();
let hh = day.getHours() * 30;
let mm = day.getMinutes() * 6;
let ss = day.getSeconds() * 6;
hr.style.transform = `rotateZ(${hh + (mm / 12)}deg)`;
mn.style.transform = `rotateZ(${mm}deg)`;
sc.style.transform = `rotateZ(${ss}deg)`;
}, 1000);
// 数字时钟
const digitalClock = document.getElementById('digital-clock');
function updateDigitalClock() {
const now = new Date();
let hours = now.getHours();
let minutes = now.getMinutes();
let seconds = now.getSeconds();
// 补零
hours = hours < 10 ? '0' + hours : hours;
minutes = minutes < 10 ? '0' + minutes : minutes;
seconds = seconds < 10 ? '0' + seconds : seconds;
digitalClock.textContent = `${hours}:${minutes}:${seconds}`;
}
// 初始化数字时钟
updateDigitalClock();
// 每秒更新数字时钟
setInterval(updateDigitalClock, 1000);
// 全屏功能
const fullscreenBtn = document.getElementById('fullscreen-btn');
fullscreenBtn.addEventListener('click', () => {
if (!document.fullscreenElement) {
document.documentElement.requestFullscreen().catch(err => {
alert(`全屏请求失败: ${err.message} (${err.name})`);
});
} else {
document.exitFullscreen();
}
});
// PWA - 注册 Service Worker
if ('serviceWorker' in navigator) {
window.addEventListener('load', () => {
navigator.serviceWorker.register('sw.js')
.then(registration => {
console.log('ServiceWorker 注册成功: ', registration.scope);
})
.catch(error => {
console.log('ServiceWorker 注册失败: ', error);
});
});
}
// PWA - 监听安装事件
let deferredPrompt;
window.addEventListener('beforeinstallprompt', (e) => {
// 阻止默认提示
e.preventDefault();
deferredPrompt = e;
// 显示安装按钮
fullscreenBtn.textContent = '安装应用';
fullscreenBtn.style.backgroundColor = '#4CAF50';
fullscreenBtn.onclick = () => {
if (deferredPrompt) {
deferredPrompt.prompt();
deferredPrompt.userChoice.then((choiceResult) => {
if (choiceResult.outcome === 'accepted') {
console.log('用户接受了安装提示');
} else {
console.log('用户拒绝了安装提示');
}
deferredPrompt = null;
});
}
};
});
window.addEventListener('appinstalled', () => {
console.log('PWA 已安装');
fullscreenBtn.style.display = 'none';
});
</script>
</body>
</html>