Skip to content

Commit 0cb837b

Browse files
committed
Finished day wesbos#2: JS + CSS clock
1 parent 4d93d2e commit 0cb837b

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

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

+27
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,40 @@
6161
background:black;
6262
position: absolute;
6363
top:50%;
64+
transform-origin:100%;
65+
transform: rotate(90deg);
66+
transition: all 0.05s;
67+
transition-timing-function: cubic-bezier(0.42, 0, 0, 2.85);
6468
}
6569

6670
</style>
6771

6872
<script>
73+
const secondHand = document.querySelector('.second-hand');
74+
const minuteHand = document.querySelector('.min-hand');
75+
const hourHand = document.querySelector('.hour-hand');
6976

77+
function setTransform(element, deg) {
78+
element.style.transform = `rotate(${deg}deg)`;
79+
}
80+
81+
function setDate() {
82+
const date = new Date()
83+
84+
const second = date.getSeconds();
85+
const secDeg = ((second / 60) * 360) + 90;
86+
setTransform(secondHand, secDeg);
87+
88+
const minute = date.getMinutes();
89+
const minDeg = ((minute / 60) * 360) + 90;
90+
setTransform(minuteHand, minDeg);
91+
92+
const hour = date.getHours();
93+
const hourDeg = ((hour / 12) * 360) + 90;
94+
setTransform(hourHand, hourDeg);
95+
}
7096

97+
setInterval(setDate, 1000);
7198
</script>
7299
</body>
73100
</html>

0 commit comments

Comments
 (0)