Visitar URL original
Merge pull request #3 from wcski/clock · wcski/JavaScript30@56068fb · GitHub
Skip to content

Commit 56068fb

Browse files
author
William Coleman
authored
Merge pull request #3 from wcski/clock
added working clock
2 parents 0a73861 + ae074b2 commit 56068fb

1 file changed

Lines changed: 30 additions & 1 deletion

File tree

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

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,41 @@
6262
background:black;
6363
position: absolute;
6464
top:50%;
65+
transform-origin: 100%;
66+
transform: rotate(90deg);
67+
transition: all 0.5s;
6568
}
6669

67-
</style>
70+
.hour-hand {
71+
background: red;
72+
}
6873

74+
</style>
75+
6976
<script>
7077

78+
const secondHand = document.querySelector('.second-hand');
79+
const minuteHand = document.querySelector('.min-hand');
80+
const hourHand = document.querySelector('hour-hand');
81+
82+
function setDate() {
83+
const now = new Date();
84+
85+
const seconds = now.getSeconds();
86+
const secondsDegrees = ((seconds / 60) * 360) + 90;
87+
secondHand.style.transform = `rotate(${secondsDegrees}deg)`;
88+
89+
const minutes = now.getMinutes();
90+
const minutesDegrees = ((minutes / 60) * 360) + 90;
91+
minuteHand.style.transform = `rotate(${minutesDegrees}deg)`;
92+
93+
const hours = now.getHours();
94+
const hoursDegrees = ((hours / 12) * 360) + 90;
95+
hourHand.style.transform = `rotate(${hoursDegrees}deg`;
96+
97+
}
98+
99+
setInterval(setDate, 1000);
71100

72101
</script>
73102
</body>

0 commit comments

Comments
 (0)