Skip to content

Commit efbccd6

Browse files
committed
Add JS Clock
1 parent c42fdc4 commit efbccd6

File tree

5 files changed

+96
-173
lines changed

5 files changed

+96
-173
lines changed

02 - JS and CSS Clock/index-FINISHED.html

Lines changed: 0 additions & 99 deletions
This file was deleted.

02 - JS and CSS Clock/index-START.html

Lines changed: 0 additions & 74 deletions
This file was deleted.

02 - JS and CSS Clock/index.html

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
4+
<head>
5+
<meta charset="UTF-8">
6+
<title>JS + CSS Clock</title>
7+
<link rel="stylesheet" href="style.css">
8+
</head>
9+
10+
<body>
11+
12+
13+
<div class="clock">
14+
<div class="clock-face">
15+
<div class="hand hour-hand"></div>
16+
<div class="hand min-hand"></div>
17+
<div class="hand second-hand"></div>
18+
</div>
19+
</div>
20+
21+
<script src="main.js"></script>
22+
23+
</body>
24+
25+
</html>

02 - JS and CSS Clock/main.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
const $secondHand = document.querySelector(".second-hand");
2+
const $minHand = document.querySelector(".min-hand");
3+
const $hourHand = document.querySelector(".hour-hand");
4+
5+
function setDate() {
6+
const now = new Date();
7+
const secounds = now.getSeconds();
8+
const secoundsDegree = ((secounds / 60) * 360) + 90;
9+
$secondHand.style.transform = `rotate(${secoundsDegree}deg)`
10+
11+
const mins = now.getMinutes();
12+
const minssDegree = ((mins / 60) * 360) + 90;
13+
$minHand.style.transform = `rotate(${minssDegree}deg)`
14+
15+
const hours = now.getHours();
16+
const hoursDegree = ((hours / 60) * 360) + 90;
17+
$hourHand.style.transform = `rotate(${hoursDegree}deg)`
18+
}
19+
20+
setInterval(() => setDate(), 1000);

02 - JS and CSS Clock/style.css

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
html {
2+
background: #018DED url(https://unsplash.it/1500/1000?image=881&blur=5);
3+
background-size: cover;
4+
font-family: 'helvetica neue';
5+
text-align: center;
6+
font-size: 10px;
7+
}
8+
9+
body {
10+
margin: 0;
11+
font-size: 2rem;
12+
display: flex;
13+
flex: 1;
14+
min-height: 100vh;
15+
align-items: center;
16+
}
17+
18+
.clock {
19+
width: 30rem;
20+
height: 30rem;
21+
border: 20px solid white;
22+
border-radius: 50%;
23+
margin: 50px auto;
24+
position: relative;
25+
padding: 2rem;
26+
box-shadow:
27+
0 0 0 4px rgba(0, 0, 0, 0.1),
28+
inset 0 0 0 3px #EFEFEF,
29+
inset 0 0 10px black,
30+
0 0 10px rgba(0, 0, 0, 0.2);
31+
}
32+
33+
.clock-face {
34+
position: relative;
35+
width: 100%;
36+
height: 100%;
37+
transform: translateY(-3px);
38+
/* account for the height of the clock hands */
39+
}
40+
41+
.hand {
42+
width: 50%;
43+
height: 6px;
44+
background: black;
45+
position: absolute;
46+
top: 50%;
47+
transform: rotate(90deg);
48+
transform-origin: 100%;
49+
transition: all 0.05s;
50+
transition-timing-function: cubic-bezier(0.55, -1.14, 0.74, 2.87);
51+
}

0 commit comments

Comments
 (0)