Skip to content

Commit 1fd9d08

Browse files
committed
Day 2.
1 parent b2eefe8 commit 1fd9d08

File tree

2 files changed

+99
-0
lines changed

2 files changed

+99
-0
lines changed

02 - JS + CSS Clock/index.html

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<title>JS + CSS Clock</title>
6+
<link rel="stylesheet" href="style.css">
7+
</head>
8+
<body>
9+
10+
<div class="clock">
11+
<div class="clock-face">
12+
<div class="hand hour-hand"></div>
13+
<div class="hand min-hand"></div>
14+
<div class="hand second-hand"></div>
15+
</div>
16+
</div>
17+
18+
<script>
19+
const hourHand = document.querySelector( '.hour-hand' );
20+
const minHand = document.querySelector( '.min-hand' );
21+
const secondHand = document.querySelector( '.second-hand' );
22+
23+
function setHand( hand, degrees ) {
24+
hand.style.transform = `rotate(${degrees}deg)`;
25+
}
26+
27+
setInterval( () => {
28+
const date = new Date();
29+
30+
setHand( hourHand, 30 * date.getHours() );
31+
setHand( minHand, 6 * date.getMinutes() );
32+
setHand( secondHand, 6 * date.getSeconds() );
33+
}, 1000 );
34+
</script>
35+
36+
</body>
37+
</html>

02 - JS + CSS Clock/style.css

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
html {
2+
background: #018ded url(http://unsplash.it/1500/1000?image=881&blur=50);
3+
background-size: cover;
4+
font-family: 'helvetica neue', sans-serif;
5+
text-align: center;
6+
font-size: 10px;
7+
}
8+
9+
body {
10+
font-size: 2rem;
11+
display: flex;
12+
flex: 1;
13+
min-height: 100vh;
14+
align-items: center;
15+
}
16+
17+
.clock {
18+
width: 30rem;
19+
height: 30rem;
20+
border: 20px solid white;
21+
border-radius: 50%;
22+
margin: 50px auto;
23+
position: relative;
24+
padding: 2rem;
25+
box-shadow: 0 0 0 4px rgba(0, 0, 0, 0.1),
26+
inset 0 0 0 3px #efefef,
27+
inset 0 0 10px black,
28+
0 0 10px rgba(0, 0, 0, 0.2);
29+
}
30+
31+
.clock-face {
32+
position: relative;
33+
width: 100%;
34+
height: 100%;
35+
}
36+
37+
.hand {
38+
position: absolute;
39+
left: 50%;
40+
bottom: 50%;
41+
height: 50%;
42+
transition: transform .05s cubic-bezier(0, 2, .5, 1);
43+
transform-origin: 50% 100%;
44+
}
45+
46+
.hand::before {
47+
content: '';
48+
display: block;
49+
position: relative;
50+
bottom: 0;
51+
border-radius: 42.5%;
52+
border: 3px solid black;
53+
height: 100%;
54+
}
55+
56+
.hour-hand {
57+
height: 37.5%;
58+
}
59+
60+
.second-hand::before {
61+
border: 2px solid red;
62+
}

0 commit comments

Comments
 (0)