Skip to content

Commit 54f52b9

Browse files
author
Greg Pfaff
committed
CSS and JS clock
1 parent 750caa8 commit 54f52b9

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

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

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
</head>
77
<body>
88

9+
<h1> JS + CSS CLOCK </h1>
910

1011
<div class="clock">
1112
<div class="clock-face">
@@ -61,12 +62,46 @@
6162
background:black;
6263
position: absolute;
6364
top:50%;
65+
transform-origin: 100%;
66+
transform: rotate(90deg);
67+
transition: all 0.05s;
68+
transition-timing-function: cubic-bezier(0.1, 2.7, 0.58, 1);
6469
}
6570

6671
</style>
6772

6873
<script>
6974

75+
const secondHand = document.querySelector('.second-hand');
76+
const minuteHand = document.querySelector('.min-hand');
77+
const hourHand = document.querySelector('.hour-hand');
78+
79+
function setDate() {
80+
// get new date
81+
const now = new Date();
82+
// get seconds of current date
83+
const seconds = now.getSeconds();
84+
// set seconds to a degree
85+
const secondsDegrees = ((seconds / 60 ) * 360) + 90;
86+
secondHand.style.transform = `rotate(${secondsDegrees}deg)`;
87+
// set degree to the transform property
88+
89+
// minute hand
90+
const minutes = now.getMinutes();
91+
const minutesDegrees = ((minutes / 60) * 360) + 90;
92+
minuteHand.style.transform = `rotate(${minutesDegrees}deg)`;
93+
94+
// hour hand
95+
96+
const hours = now.getHours();
97+
const hoursDegrees = ((hours / 12) * 360) + 90;
98+
hourHand.style.transform = `rotate(${hoursDegrees}deg)`;
99+
100+
101+
102+
}
103+
104+
setInterval(setDate, 1000)
70105

71106
</script>
72107
</body>

0 commit comments

Comments
 (0)