-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
124 lines (110 loc) · 3.64 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Hypnotic clock - Animated ticking clock - @nyan-matt</title>
<style>
body {
margin-top: 16%;
background-color: #C9C9C9;
filter: grayscale(1);
font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
}
.wrapper {
display: grid;
grid-template-columns: auto;
margin: 0 48px;
}
@media (min-width: 1279px) {
.wrapper {
margin: 0 256px;
}
}
@media (maX-width: 1023px) {
.wrapper {
margin: 0 128px;
}
}
@media (max-width: 639px) {
.wrapper {
margin: 0 24px;
}
}
.description {
grid-column: span 6;
color: #787878;
margin-top:32px;
text-align: center;
}
img {
width: 100%;
max-width: 100%;
height:auto;
filter: grayscale(1);
box-shadow: inset 0px 1px 4px 0px rgba(0,0,0,0.22);
border: 1px solid #dfdfdf;
outline: 1px solid rgba(0,0,0,0.20);
}
h1 {font-size: 14px; font-weight: 400;}
p {line-height:24px}
</style>
</head>
<body>
<div class="wrapper">
<img id="hour1" srcset="" alt="hour digit tens place">
<img id="hour2" srcset="" alt="hour digit ones place">
<img id="minute1" srcset="" alt="minute digit tens place">
<img id="minute2" srcset="" alt="minute digit ones place">
<img id="second1" srcset="" alt="second digit tens place">
<img id="second2" srcset="" alt="second digit ones place">
<div class="description">
<h1>Clock study</h1>
</div>
</div>
<script>
let previousTime = '';
function displayCurrentTime() {
const now = new Date();
const hours = String(now.getHours()).padStart(2, '0');
const minutes = String(now.getMinutes()).padStart(2, '0');
const seconds = String(now.getSeconds()).padStart(2, '0');
const currentTime = hours + minutes + seconds;
if (currentTime !== previousTime) {
for (let i = 0; i < currentTime.length; i++) {
const elementId = ['hour1', 'hour2', 'minute1', 'minute2', 'second1', 'second2'][i];
const element = document.getElementById(elementId);
const staticSrc = `${currentTime[i]}.gif`; // static image src
const animatedSrc = `${currentTime[i]}.webp`; // animated image src
if (previousTime === '' || currentTime[i] !== previousTime[i]) {
// Set the animated image src if the digit changed
element.srcset = animatedSrc;
} else {
// Set the static image src if the digit didn't change
element.srcset = staticSrc;
}
}
previousTime = currentTime;
}
}
// Initialize static images
function initializeClock() {
const now = new Date();
const hours = String(now.getHours()).padStart(2, '0');
const minutes = String(now.getMinutes()).padStart(2, '0');
const seconds = String(now.getSeconds()).padStart(2, '0');
const currentTime = hours + minutes + seconds;
for (let i = 0; i < currentTime.length; i++) {
const elementId = ['hour1', 'hour2', 'minute1', 'minute2', 'second1', 'second2'][i];
const element = document.getElementById(elementId);
const staticSrc = `${currentTime[i]}.gif`; // static image src
element.srcset = staticSrc;
}
}
// Initialize the clock with static images
initializeClock();
// Call the function every second to display the current time
setInterval(displayCurrentTime, 1000);
</script>
</body>
</html>