Visitar URL original
day two · wesbos/JavaScript30@44ddb81 · GitHub
Skip to content

Commit 44ddb81

Browse files
committed
day two
1 parent b95a972 commit 44ddb81

1 file changed

Lines changed: 20 additions & 2 deletions

File tree

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

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,31 @@
6363
background: black;
6464
position: absolute;
6565
top: 50%;
66+
transform-origin: 100%;
67+
transform: rotate(90deg);
68+
transition: all 0.5s;
69+
transition-timing-function: cubic-bezier(0.45, 2.51, 0.58, 1);
6670
}
6771

6872
</style>
6973

7074
<script>
71-
72-
75+
const secondHand = document.querySelector(".second-hand");
76+
const minuteHand = document.querySelector(".min-hand");
77+
const hourHand = document.querySelector(".hour-hand");
78+
function setTime() {
79+
const now = new Date();
80+
const seconds = now.getSeconds();
81+
const secDegrees = (seconds / 60 * 360) + 90;
82+
secondHand.style.transform = `rotate(${secDegrees}deg)`;
83+
const minutes = now.getMinutes();
84+
const minDegrees = (minutes / 60 * 360) + 90;
85+
minuteHand.style.transform = `rotate(${minDegrees}deg)`;
86+
const hours = now.getHours();
87+
const hourDegrees = (hours / 12 * 360) + 90;
88+
hourHand.style.transform = `rotate(${hourDegrees}deg)`;
89+
}
90+
setInterval(setTime, 1000);
7391
</script>
7492
</body>
7593
</html>

0 commit comments

Comments
 (0)