Skip to content

Commit 5df63c0

Browse files
committed
clock complete
1 parent aecacf7 commit 5df63c0

3 files changed

Lines changed: 75 additions & 54 deletions

File tree

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

Lines changed: 2 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
<head>
44
<meta charset="UTF-8">
55
<title>JS + CSS Clock</title>
6+
<link rel='stylesheet' href='styles/main.css'>
67
</head>
78
<body>
89

@@ -15,59 +16,6 @@
1516
</div>
1617
</div>
1718

18-
19-
<style>
20-
html {
21-
background:#018DED url(http://unsplash.it/1500/1000?image=881&blur=50);
22-
background-size:cover;
23-
font-family:'helvetica neue';
24-
text-align: center;
25-
font-size: 10px;
26-
}
27-
28-
body {
29-
font-size: 2rem;
30-
display:flex;
31-
flex:1;
32-
min-height: 100vh;
33-
align-items: center;
34-
}
35-
36-
.clock {
37-
width: 30rem;
38-
height: 30rem;
39-
border:20px solid white;
40-
border-radius:50%;
41-
margin:50px auto;
42-
position: relative;
43-
padding:2rem;
44-
box-shadow:
45-
0 0 0 4px rgba(0,0,0,0.1),
46-
inset 0 0 0 3px #EFEFEF,
47-
inset 0 0 10px black,
48-
0 0 10px rgba(0,0,0,0.2);
49-
}
50-
51-
.clock-face {
52-
position: relative;
53-
width: 100%;
54-
height: 100%;
55-
transform: translateY(-3px); /* account for the height of the clock hands */
56-
}
57-
58-
.hand {
59-
width:50%;
60-
height:6px;
61-
background:black;
62-
position: absolute;
63-
top:50%;
64-
}
65-
66-
</style>
67-
68-
<script>
69-
70-
71-
</script>
19+
<script src='js/app.js'></script>
7220
</body>
7321
</html>

02 - JS + CSS Clock/js/app.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
const secondHand = document.querySelector('.second-hand');
2+
const minHand = document.querySelector('.min-hand');
3+
const hourHand = document.querySelector('.hour-hand');
4+
5+
6+
7+
function setDate() {
8+
const now = new Date();
9+
10+
const seconds = now.getSeconds();
11+
const secondsDegrees = ((seconds / 60) * 360) + 90;
12+
secondHand.style.transform = `rotate(${secondsDegrees}deg)`;
13+
14+
const minutes = now.getMinutes();
15+
const minutesDegrees = ((minutes / 60) * 360) + 90;
16+
minHand.style.transform = `rotate(${minutesDegrees}deg)`;
17+
18+
const hour = now.getHours();
19+
const hourDegrees = ((hour / 12) * 360) + 90;
20+
hourHand.style.transform = `rotate(${hourDegrees}deg)`;
21+
22+
}
23+
24+
setInterval(setDate, 1000);
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
html {
2+
background:#018DED url(http://unsplash.it/1500/1000?image=881&blur=50);
3+
background-size:cover;
4+
font-family:'helvetica neue';
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:
26+
0 0 0 4px rgba(0,0,0,0.1),
27+
inset 0 0 0 3px #EFEFEF,
28+
inset 0 0 10px black,
29+
0 0 10px rgba(0,0,0,0.2);
30+
}
31+
32+
.clock-face {
33+
position: relative;
34+
width: 100%;
35+
height: 100%;
36+
transform: translateY(-3px); /* account for the height of the clock hands */
37+
}
38+
39+
.hand {
40+
width:50%;
41+
height:6px;
42+
background:black;
43+
position: absolute;
44+
top:50%;
45+
transform-origin: 100%;
46+
transform: rotate(90deg);
47+
transition: all 0.05s;
48+
transition-timing-function: cubic-bezier(0.1, 2.7, 0.58, 1);
49+
}

0 commit comments

Comments
 (0)