Skip to content

Commit 3ac60fe

Browse files
committed
clock functions
1 parent 38a754c commit 3ac60fe

1 file changed

Lines changed: 24 additions & 2 deletions

File tree

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

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414
<div class="hand second-hand"></div>
1515
</div>
1616
</div>
17-
17+
<label for="">Rate</label>
18+
<input type="opti">
1819

1920
<style>
2021
html {
@@ -61,12 +62,33 @@
6162
background:black;
6263
position: absolute;
6364
top:50%;
65+
transform-origin: 100%;
66+
transform: rotate(90deg);
67+
transform: all 0.05s;
68+
transition-timing-function: cubic-bezier(0.1, 2.7 .58, 1);
6469
}
6570

6671
</style>
67-
6872
<script>
6973

74+
const hrHand = document.querySelector('.hour-hand')
75+
const minHand = document.querySelector('.min-hand')
76+
const secHand = document.querySelector('.second-hand')
77+
78+
const setDate = ()=>{
79+
const now = new Date();
80+
const hours = now.getHours();
81+
const minutes = now.getMinutes();
82+
const seconds = now.getSeconds();
83+
const hrDegree = (hours / 12) * 360 + 90;
84+
const minDegree = (minutes / 60) * 360 + 90;
85+
const secDegree = (seconds / 60) * 360 + 90;
86+
hrHand.style.transform = `rotate(${hrDegree}deg)`
87+
minHand.style.transform = `rotate(${minDegree}deg)`
88+
secHand.style.transform = `rotate(${secDegree}deg)`
89+
}
90+
91+
setInterval(setDate, 1000)
7092

7193
</script>
7294
</body>

0 commit comments

Comments
 (0)