-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
65 lines (52 loc) · 1.94 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>New Year Countdown</title>
<style>
.clock {
width: 200px;
height: 200px;
border: 2px solid black;
border-radius: 50%;
display: flex;
justify-content: center;
align-items: center;
font-size: 24px;
}
</style>
</head>
<body>
<div id="clock" class="clock"></div>
<div id="countdown"></div>
<script>
function updateClock() {
const clock = document.getElementById("clock");
const currentTime = new Date();
const seconds = currentTime.getSeconds();
const minutes = currentTime.getMinutes();
const hours = currentTime.getHours();
const secondsAngle = (seconds / 60) * 360;
const minutesAngle = ((minutes * 60 + seconds) / 3600) * 360;
const hoursAngle = ((hours * 3600 + minutes * 60 + seconds) / 43200) * 360;
clock.style.transform = `rotate(${secondsAngle}deg)`;
clock.innerHTML = `${hours.toString().padStart(2, '0')}:${minutes.toString().padStart(2, '0')}:${seconds.toString().padStart(2, '0')}`;
setTimeout(updateClock, 1000);
}
function updateCountdown() {
const countdown = document.getElementById("countdown");
const now = new Date();
const newYear = new Date(now.getFullYear() + 1, 0, 1);
const timeLeft = newYear - now;
const days = Math.floor(timeLeft / (1000 * 60 * 60 * 24));
const hours = Math.floor((timeLeft % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
const minutes = Math.floor((timeLeft % (1000 * 60 * 60)) / (1000 * 60));
countdown.innerHTML = `剩下的时间直到新年: ${days} 天, ${hours} 小时, ${minutes} 分钟`;
setTimeout(updateCountdown, 1000);
}
updateClock();
updateCountdown();
</script>
</body>
</html>