Skip to content

Commit 4b2cc5a

Browse files
committed
initial
0 parents  commit 4b2cc5a

File tree

4 files changed

+111
-0
lines changed

4 files changed

+111
-0
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Analog Clock Challenge
2+
3+
-Pure JavaScript

index.html

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<!DOCTYPE html>
2+
<html lang="en-US">
3+
4+
<head>
5+
<meta charset="UTF-8">
6+
<meta name="viewport" content="width=device-width, initial-scale=1">
7+
<title>A Digital Analog Clock</title>
8+
<link rel="stylesheet" href="style.css" type="text/css" media="all">
9+
<script src="script.js" defer></script>
10+
</head>
11+
12+
<body>
13+
<main class="main">
14+
<div class="clockbox">
15+
<svg id="clock" xmlns="http://www.w3.org/2000/svg" width="600" height="600" viewBox="0 0 600 600">
16+
<g id="face">
17+
<circle class="circle" cx="300" cy="300" r="253.9"/>
18+
<path class="hour-marks" d="M300.5 94V61M506 300.5h32M300.5 506v33M94 300.5H60M411.3 107.8l7.9-13.8M493 190.2l13-7.4M492.1 411.4l16.5 9.5M411 492.3l8.9 15.3M189 492.3l-9.2 15.9M107.7 411L93 419.5M107.5 189.3l-17.1-9.9M188.1 108.2l-9-15.6"/>
19+
<circle class="mid-circle" cx="300" cy="300" r="16.2"/>
20+
</g>
21+
<g id="hour">
22+
<path class="hour-arm" d="M300.5 298V142"/>
23+
<circle class="sizing-box" cx="300" cy="300" r="253.9"/>
24+
</g>
25+
<g id="minute">
26+
<path class="minute-arm" d="M300.5 298V67"/>
27+
<circle class="sizing-box" cx="300" cy="300" r="253.9"/>
28+
</g>
29+
<g id="second">
30+
<path class="second-arm" d="M300.5 350V55"/>
31+
<circle class="sizing-box" cx="300" cy="300" r="253.9"/>
32+
</g>
33+
</svg>
34+
</div><!-- .clockbox -->
35+
</main>
36+
37+
</body>
38+
39+
</html>

script.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
const HOURHAND = document.querySelector("#hour");
2+
const MINUTEHAND = document.querySelector("#minute");
3+
const SECONDHAND = document.querySelector("#second");

style.css

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
/* Layout */
2+
.main {
3+
display: flex;
4+
padding: 2em;
5+
height: 90vh;
6+
justify-content: center;
7+
align-items: middle;
8+
}
9+
10+
.clockbox,
11+
#clock {
12+
width: 100%;
13+
}
14+
15+
/* Clock styles */
16+
.circle {
17+
fill: none;
18+
stroke: #000;
19+
stroke-width: 9;
20+
stroke-miterlimit: 10;
21+
}
22+
23+
.mid-circle {
24+
fill: #000;
25+
}
26+
.hour-marks {
27+
fill: none;
28+
stroke: #000;
29+
stroke-width: 9;
30+
stroke-miterlimit: 10;
31+
}
32+
33+
.hour-arm {
34+
fill: none;
35+
stroke: #000;
36+
stroke-width: 17;
37+
stroke-miterlimit: 10;
38+
}
39+
40+
.minute-arm {
41+
fill: none;
42+
stroke: #000;
43+
stroke-width: 11;
44+
stroke-miterlimit: 10;
45+
}
46+
47+
.second-arm {
48+
fill: none;
49+
stroke: #000;
50+
stroke-width: 4;
51+
stroke-miterlimit: 10;
52+
}
53+
54+
/* Transparent box ensuring arms center properly. */
55+
.sizing-box {
56+
fill: none;
57+
}
58+
59+
/* Make all arms rotate around the same center point. */
60+
/* Optional: Use transition for animation. */
61+
#hour,
62+
#minute,
63+
#second {
64+
transform-origin: 300px 300px;
65+
transition: transform .5s ease-in-out;
66+
}

0 commit comments

Comments
 (0)