-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbackground_colour_time_of_day.html
More file actions
46 lines (42 loc) · 1.08 KB
/
background_colour_time_of_day.html
File metadata and controls
46 lines (42 loc) · 1.08 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Time-Based Background</title>
<style>
body {
transition: background-color 1s ease;
color: white;
font-family: sans-serif;
text-align: center;
padding-top: 20%;
}
</style>
</head>
<body>
<p>The background color changes based on the time of day.</p>
<script>
function setBackgroundByTime() {
const hour = new Date().getHours();
let bgColor;
if (hour >= 6 && hour < 12) {
// Morning
bgColor = "#FFD580"; // light orange
} else if (hour >= 12 && hour < 18) {
// Afternoon
bgColor = "#87CEEB"; // light blue
} else if (hour >= 18 && hour < 21) {
// Evening
bgColor = "#FFA07A"; // salmon
} else {
// Night
bgColor = "#2F4F4F"; // dark slate gray
}
document.body.style.backgroundColor = bgColor;
}
// Set background on page load
setBackgroundByTime();
</script>
</body>
</html>