Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 274b88f

Browse files
author
Jin Xu
committed
course wesbos#2 finished
1 parent e09fa7f commit 274b88f

File tree

2 files changed

+60
-3
lines changed

2 files changed

+60
-3
lines changed

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

Lines changed: 59 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
<style>
2020
html {
21-
background:#018DED url(http://unsplash.it/1500/1000?image=881&blur=50);
21+
background:#018DED;
2222
background-size:cover;
2323
font-family:'helvetica neue';
2424
text-align: center;
@@ -55,18 +55,75 @@
5555
transform: translateY(-3px); /* account for the height of the clock hands */
5656
}
5757

58+
.clock-face::after{
59+
position: absolute;
60+
content: '' ;
61+
left: 50%;
62+
top: 50%;
63+
width: 20px;
64+
height: 20px;
65+
background: #fff;
66+
transform: translate(-50%, -50%);
67+
border-radius: 50%;
68+
}
69+
5870
.hand {
5971
width:50%;
6072
height:6px;
61-
background:black;
6273
position: absolute;
6374
top:50%;
75+
transform: rotate(90deg);
76+
transform-origin: right center;
77+
}
78+
.hour-hand {
79+
background: mediumvioletred;
80+
width: 30%;
81+
margin-top: -3px;
82+
margin-left: 20%;
83+
}
84+
.min-hand {
85+
margin-top: -3px;
86+
background: mediumspringgreen;
87+
}
88+
.second-hand {
89+
background: greenyellow;
90+
height: 4px;
91+
margin-top: -2px;
6492
}
6593

6694
</style>
6795

6896
<script>
6997

98+
let h, m, s;
99+
100+
// get the current hour min & sec
101+
function getTime() {
102+
let current = new Date();
103+
h = current.getHours();
104+
m = current.getMinutes();
105+
s = current.getSeconds();
106+
}
107+
108+
// fn to change hour min & sec to angle
109+
let toAngle = n => (90 + n / 60 * 360);
110+
111+
let updateAngle = (tar, angle) => {
112+
tar.style.transform = `rotate(${angle}deg)`;
113+
}
114+
115+
let renderClock = () => {
116+
getTime();
117+
((domObj) => {
118+
for(dom in domObj) {
119+
updateAngle(document.querySelector(`.${dom}`), toAngle(domObj[dom]))
120+
}
121+
})({'hour-hand': h, 'min-hand': m, 'second-hand': s});
122+
}
123+
124+
renderClock();
125+
126+
setInterval(renderClock, 1000);
70127

71128
</script>
72129
</body>

readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
> Folked repo for practice and fun!
66
77
1. [x] ~~JavaScript Drum Kit~~
8-
2. [ ] JS + CSS Clock
8+
2. [x] ~~JS + CSS Clock ~~
99
3. [ ] CSS Variables
1010
4. [ ] Array Cardio, Day 1
1111
5. [ ] Flex Panel Gallery

0 commit comments

Comments
 (0)