Skip to content

Commit 8241918

Browse files
committed
Responsive design
1 parent 05cca26 commit 8241918

File tree

3 files changed

+92
-10
lines changed

3 files changed

+92
-10
lines changed

.DS_Store

2 KB
Binary file not shown.

clock_demo/index.html

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,32 +6,47 @@
66

77
<style>
88
body {
9+
margin: 0;
910
display: flex;
1011
justify-content: center;
1112
align-items: center;
12-
height: 90vh;
13-
background: white;
13+
min-height: 100vh;
1414
}
1515

1616
.clock {
1717
position: relative;
18-
width: 600px;
19-
height: 600px;
18+
width: min(80vw, 80vh);
19+
aspect-ratio: 1 / 1;
2020
}
2121

22+
/* Background image (static) */
23+
.background {
24+
position: absolute;
25+
inset: 0;
26+
width: 100%;
27+
height: 100%;
28+
object-fit: contain;
29+
pointer-events: none;
30+
}
31+
32+
/* Clock hands */
2233
.hand {
2334
position: absolute;
2435
top: 50%;
2536
left: 50%;
26-
transform-origin: 50% 50%; /* center */
37+
width: auto;
38+
height: 100%;
39+
max-height: 100%;
40+
transform-origin: 50% 50%;
2741
transform: translate(-50%, -50%) rotate(0deg);
42+
pointer-events: none;
2843
}
2944

30-
/* Optional sizing */
31-
.background { height: 600px; }
32-
#hours { height: 600px; }
33-
#minutes { height: 600px; }
34-
#seconds { height: 600px; }
45+
/* Scale individual hands */
46+
#hours { height: 90%; }
47+
#minutes { height: 90%; }
48+
#seconds { height: 90%; }
49+
3550
</style>
3651
</head>
3752

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<title>Clock demo</title>
6+
7+
<style>
8+
body {
9+
display: flex;
10+
justify-content: center;
11+
align-items: center;
12+
height: 90vh;
13+
background: white;
14+
}
15+
16+
.clock {
17+
position: relative;
18+
width: 600px;
19+
height: 600px;
20+
}
21+
22+
.hand {
23+
position: absolute;
24+
top: 50%;
25+
left: 50%;
26+
transform-origin: 50% 50%; /* center */
27+
transform: translate(-50%, -50%) rotate(0deg);
28+
}
29+
30+
/* Optional sizing */
31+
.background { height: 600px; }
32+
#hours { height: 600px; }
33+
#minutes { height: 600px; }
34+
#seconds { height: 600px; }
35+
</style>
36+
</head>
37+
38+
<body>
39+
<div class="clock">
40+
<img src="background.png" class="background" alt="Clock background">
41+
<img src="hours.png" id="hours" class="hand">
42+
<img src="minutes.png" id="minutes" class="hand">
43+
<img src="seconds.png" id="seconds" class="hand">
44+
</div>
45+
46+
<script>
47+
const h = document.getElementById("hours");
48+
const m = document.getElementById("minutes");
49+
const s = document.getElementById("seconds");
50+
51+
function updateClock() {
52+
const now = new Date();
53+
54+
const seconds = now.getSeconds();
55+
const minutes = now.getMinutes() + seconds / 60;
56+
const hours = (now.getHours() % 12) + minutes / 60;
57+
58+
h.style.transform = `translate(-50%, -50%) rotate(${hours * 30}deg)`;
59+
m.style.transform = `translate(-50%, -50%) rotate(${minutes * 6}deg)`;
60+
s.style.transform = `translate(-50%, -50%) rotate(${seconds * 6}deg)`;
61+
}
62+
63+
updateClock();
64+
setInterval(updateClock, 10);
65+
</script>
66+
</body>
67+
</html>

0 commit comments

Comments
 (0)