Skip to content

Commit e0e3616

Browse files
committed
cleaned up timer
1 parent 468e433 commit e0e3616

File tree

1 file changed

+10
-19
lines changed

1 file changed

+10
-19
lines changed

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

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -62,39 +62,30 @@
6262
background: black;
6363
position: absolute;
6464
top: 50%;
65+
transform-origin: 100%;
66+
transition: all 1s;
67+
transition-timing-function: ease-in-out;
6568
}
6669

6770
</style>
6871

6972
<script>
70-
71-
let hours = new Date().getHours() % 12;
72-
let hourHand = document.getElementsByClassName('hour-hand')[0];
73-
hourHand.setAttribute('style', `transform: rotate(${90 + ((360 / 12) * hours)}deg); transform-origin: bottom right;`)
74-
75-
let minutes = new Date().getMinutes();
76-
let minutesHand = document.getElementsByClassName('min-hand')[0];
77-
minutesHand.setAttribute('style', `transform: rotate(${90 + ((360 / (60)) * minutes)}deg); transform-origin: bottom right;`)
78-
79-
let seconds = new Date().getSeconds();
80-
let secondsHand = document.getElementsByClassName('second-hand')[0];
81-
secondsHand.setAttribute('style', `transform: rotate(${90 + ((360 / (60)) * seconds)}deg); transform-origin: bottom right;`)
82-
83-
setInterval(() => {
73+
let setTime = () => {
8474
let seconds = new Date().getSeconds();
8575
let secondsHand = document.getElementsByClassName('second-hand')[0];
86-
secondsHand.setAttribute('style', `transform: rotate(${90 + ((360 / (60)) * seconds)}deg); transform-origin: bottom right;`)
76+
secondsHand.setAttribute('style', `transform: rotate(${90 + ((360 / (60)) * seconds)}deg); transform-origin: 100%;`)
8777

8878
let hours = new Date().getHours() % 12;
8979
let hourHand = document.getElementsByClassName('hour-hand')[0];
90-
hourHand.setAttribute('style', `transform: rotate(${90 + ((360 / 12) * hours)}deg); transform-origin: bottom right;`)
80+
hourHand.setAttribute('style', `transform: rotate(${90 + ((360 / 12) * hours)}deg); transform-origin: 100%;`)
9181

9282
let minutes = new Date().getMinutes();
9383
let minutesHand = document.getElementsByClassName('min-hand')[0];
94-
minutesHand.setAttribute('style', `transform: rotate(${90 + ((360 / (60)) * minutes)}deg); transform-origin: bottom right;`)
95-
}, 1000);
84+
minutesHand.setAttribute('style', `transform: rotate(${90 + ((360 / (60)) * minutes)}deg); transform-origin: 100%;`)
85+
}
9686

97-
// console.log('seconds', seconds);
87+
setInterval(() => {setTime()}, 1000);
88+
setTime();
9889

9990

10091
</script>

0 commit comments

Comments
 (0)