Skip to content

Commit 3241fa1

Browse files
committed
Completed exercise wesbos#2 of JS30.
1 parent f7f0c55 commit 3241fa1

File tree

1 file changed

+37
-2
lines changed

1 file changed

+37
-2
lines changed

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

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,16 +58,51 @@
5858

5959
.hand {
6060
width:50%;
61-
height:6px;
61+
height:2px;
6262
background:black;
6363
position: absolute;
64-
top:50%;
64+
top:calc(50% - 1px);
65+
transform-origin: 100%;
66+
transform: rotate(90deg);
67+
transition-timing-function: cubic-bezier(0, 1.21, 0.51, 1.03);
68+
}
69+
70+
.hour-hand {
71+
width:35%;
72+
height:6px;
73+
left:15%;
74+
top:calc(50% - 3px);
75+
}
76+
77+
.min-hand {
78+
width:45%;
79+
height:4px;
80+
left:5%;
81+
top:calc(50% - 2px);
6582
}
6683

6784
</style>
6885

6986
<script>
87+
const hoursHand = document.querySelector(`.hour-hand`);
88+
const minsHand = document.querySelector(`.min-hand`);
89+
const secondsHand = document.querySelector(`.second-hand`);
90+
91+
function setDate() {
92+
const now = new Date();
93+
const hours = now.getHours();
94+
const mins = now.getMinutes();
95+
const seconds = now.getSeconds();
96+
const hoursDegrees = (hours/12) * 360 + (mins/60) * 360/12 + 90; //adding mins angles as well.. to avoid the hour hand jumping each hour
97+
const minsDegrees = (mins/60) * 360 + (seconds/60) * 360/60 + 90; //adding seconds angles as well.. to avoid the hour hand jumping each minute
98+
const secondsDegrees = (seconds/60) * 360 + 90;
99+
100+
hoursHand.style.transform = `rotate(${hoursDegrees}deg)`;
101+
minsHand.style.transform = `rotate(${minsDegrees}deg)`;
102+
secondsHand.style.transform = `rotate(${secondsDegrees}deg)`;
103+
}
70104

105+
setInterval(setDate, 1000);
71106

72107
</script>
73108
</body>

0 commit comments

Comments
 (0)