Skip to content

Commit 14253eb

Browse files
committed
Move styling to separate file & add additional styling
1 parent 4fe70f9 commit 14253eb

2 files changed

Lines changed: 55 additions & 80 deletions

File tree

02 - JS + CSS Clock/index.html

Lines changed: 2 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -3,94 +3,16 @@
33
<head>
44
<meta charset="UTF-8">
55
<title>JS + CSS Clock</title>
6+
<link rel="stylesheet" href="style.css" media="screen" title="no title">
67
</head>
78
<body>
8-
9-
109
<div class="clock">
1110
<div class="clock-face">
1211
<div class="hand hour-hand"></div>
1312
<div class="hand min-hand"></div>
1413
<div class="hand second-hand"></div>
1514
</div>
1615
</div>
17-
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-
transform-origin: 100%;
65-
transform: rotate(90deg);
66-
transition: all 0.05s;
67-
transition-timing-function: cubic-bezier(0.1, 2.7, 0.58, 1);
68-
}
69-
</style>
70-
71-
<script>
72-
const secondHand = document.querySelector('.second-hand');
73-
const minsHand = document.querySelector('.min-hand');
74-
const hourHand = document.querySelector('.hour-hand');
75-
76-
function setDate() {
77-
const now = new Date();
78-
79-
const seconds = now.getSeconds();
80-
const secondsDegrees = ((seconds / 60) * 360) + 90;
81-
secondHand.style.transform = `rotate(${secondsDegrees}deg)`;
82-
83-
const mins = now.getMinutes();
84-
const minsDegrees = ((mins / 60) * 360) + 90;
85-
minsHand.style.transform = `rotate(${minsDegrees}deg)`;
86-
87-
const hour = now.getMinutes();
88-
const hourDegrees = ((mins / 12) * 360) + 90;
89-
hourHand.style.transform = `rotate(${hourDegrees}deg)`;
90-
}
91-
92-
setInterval(setDate, 1000);
93-
94-
</script>
16+
<script type="text/javascript" src="main.js"></script>
9517
</body>
9618
</html>

02 - JS + CSS Clock/style.css

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
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.57, 2.01, 0.18, 0.88);
49+
}
50+
51+
.no-transition {
52+
transition: none;
53+
}

0 commit comments

Comments
 (0)