-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
49 lines (42 loc) · 1.42 KB
/
index.html
File metadata and controls
49 lines (42 loc) · 1.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>JS + CSS Clock</title>
<link rel="stylesheet" type="text/css" href="style.css" />
</head>
<body>
<div class="clock">
<div class="clock-face">
<div class="hand hour-hand"></div>
<div class="hand minute-hand"></div>
<div class="hand second-hand"></div>
</div>
</div>
<script>
// Grab the clock hands
const secondHand = document.querySelector('.second-hand');
const minuteHand = document.querySelector('.minute-hand');
const hourHand = document.querySelector('.hour-hand');
function setDate() {
// Grab date & time
const now = new Date();
const seconds = now.getSeconds();
const minutes = now.getMinutes();
const hours = now.getHours();
// Change seconds, minutes, and hours to degrees
const secondsToDegrees = ((seconds / 60) * 360) + 90;
const minutesToDegrees = ((minutes / 60) * 360) + 90;
const hoursToDegrees = ((hours / 12) * 360) + 90;
// Set position of clock hands
secondHand.style.transform = `rotate(${secondsToDegrees}deg)`;
minuteHand.style.transform = `rotate(${minutesToDegrees}deg)`;
hourHand.style.transform = `rotate(${hoursToDegrees}deg)`;
// Log time to console
console.log(`${hours} : ${minutes} : ${seconds}`);
}
// Update clock every second
setInterval(setDate, 1000);
</script>
</body>
</html>