Visitar URL original
Start day 2 · wesbos/JavaScript30@02fa4ac · GitHub
Skip to content

Commit 02fa4ac

Browse files
committed
Start day 2
1 parent 0c74409 commit 02fa4ac

1 file changed

Lines changed: 57 additions & 23 deletions

File tree

‎02_js_css_clock/index-START.html‎

Lines changed: 57 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -5,42 +5,39 @@
55
<title>JS + CSS Clock</title>
66
</head>
77
<body>
8-
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>
8+
<div class="clock">
9+
<div class="clock-face">
10+
<div class="hand hour-hand"></div>
11+
<div class="hand minute-hand"></div>
12+
<div class="hand second-hand"></div>
1613
</div>
17-
14+
</div>
1815

1916
<style>
2017
html {
21-
background:#018DED url(http://unsplash.it/1500/1000?image=881&blur=50);
22-
background-size:cover;
23-
font-family:'helvetica neue';
18+
background: #018DED url(http://unsplash.it/1500/1000?image=881&blur=50);
19+
background-size: cover;
20+
font-family: 'helvetica neue';
2421
text-align: center;
2522
font-size: 10px;
2623
}
2724

2825
body {
2926
font-size: 2rem;
30-
display:flex;
31-
flex:1;
27+
display: flex;
28+
flex: 1;
3229
min-height: 100vh;
3330
align-items: center;
3431
}
3532

3633
.clock {
3734
width: 30rem;
3835
height: 30rem;
39-
border:20px solid white;
40-
border-radius:50%;
41-
margin:50px auto;
36+
border: 20px solid white;
37+
border-radius: 50%;
38+
margin: 50px auto;
4239
position: relative;
43-
padding:2rem;
40+
padding: 2rem;
4441
box-shadow:
4542
0 0 0 4px rgba(0,0,0,0.1),
4643
inset 0 0 0 3px #EFEFEF,
@@ -52,22 +49,59 @@
5249
position: relative;
5350
width: 100%;
5451
height: 100%;
55-
transform: translateY(-3px); /* account for the height of the clock hands */
52+
transform: translateY(-3px); /* account for height of clock hands */
5653
}
5754

5855
.hand {
59-
width:50%;
60-
height:6px;
61-
background:black;
56+
height: 6px;
57+
background: black;
6258
position: absolute;
63-
top:50%;
59+
top: 50%;
60+
transform: rotate(90deg);
61+
transform-origin: 100%;
62+
transition: all 0.05s;
63+
transition-timing-function: cubic-bezier(0.1, 2.7, 0.58, 1);
64+
}
65+
66+
.second-hand {
67+
width: 50%;
68+
height: 4px;
69+
}
70+
71+
.minute-hand {
72+
width: 50%;
6473
}
6574

75+
.hour-hand {
76+
width: 50%;
77+
}
6678
</style>
6779

6880
<script>
81+
function rotateHand(hand, angle) {
82+
angle += 90;
83+
hand.style.transform = (`rotate(${angle.toString()}deg)`);
84+
}
85+
86+
function setTime() {
87+
const now = new Date();
88+
const angles = [
89+
now.getSeconds() * 6,
90+
now.getMinutes() * 6,
91+
now.getHours() * 30,
92+
];
93+
94+
for (let i = 0; i < 3; i++) { rotateHand(hands[i], angles[i]); }
95+
}
6996

97+
const hands = [
98+
document.getElementsByClassName('second-hand')[0],
99+
document.getElementsByClassName('minute-hand')[0],
100+
document.getElementsByClassName('hour-hand')[0],
101+
];
70102

103+
window.onload = setTime;
104+
setInterval(setTime, 1000);
71105
</script>
72106
</body>
73107
</html>

0 commit comments

Comments
 (0)