-
Notifications
You must be signed in to change notification settings - Fork 0
/
snow.html
102 lines (82 loc) · 3.36 KB
/
snow.html
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="icon" type="image/png" href="assets/images/CheerLights-Icon.png">
<title>CheerLights JavaScript Widget - Snow</title>
<meta name="description" content="A widget that displays falling snowflakes using the CheerLights JavaScript library." />
<style>
:root {
--primary-color: white;
--secondary-color: oldlace;
}
body {
cursor: pointer;
height: 100vh;
margin: 0;
}
.snowflake {
position: fixed;
top: -10px;
color: var(--primary-color);
user-select: none;
cursor: default;
animation: fall linear forwards;
text-shadow: 0 0 3px rgba(0, 0, 0, 0.3),
2px 2px 5px rgba(0, 0, 0, 0.2);
}
@keyframes fall {
to {
transform: translateY(100vh);
}
}
</style>
</head>
<body>
<script src="https://cdn.jsdelivr.net/gh/cheerlights/[email protected]/cheerlights.js"></script>
<script>
const REFRESH_INTERVAL = 5000;
const CHEERLIGHTS_URL = 'https://cheerlights.com/cheerlights-javascript-widgets/';
// get root color variable values
const PRIMARY_COLOR = getComputedStyle(document.documentElement).getPropertyValue('--primary-color').trim();
const SECONDARY_COLOR = getComputedStyle(document.documentElement).getPropertyValue('--secondary-color').trim();
// get current cheerlights color
CheerLights.getColor(setBodyBackgroundColor);
// refresh cheerlights color every 5 seconds
setInterval(() => CheerLights.getColor(setBodyBackgroundColor), REFRESH_INTERVAL);
function setBodyBackgroundColor(color) {
if (!color || !color.htmlName) {
console.error('Invalid color data received');
return;
}
document.body.style.backgroundColor = color.htmlName;
document.body.title = `Current CheerLights color: ${color.htmlName}`;
if (color.htmlName === PRIMARY_COLOR) {
document.documentElement.style.setProperty('--primary-color', SECONDARY_COLOR);
}
else {
document.documentElement.style.setProperty('--primary-color', PRIMARY_COLOR);
}
}
function createSnowflake() {
const snowflake = document.createElement('div');
snowflake.className = 'snowflake';
snowflake.style.left = Math.random() * 100 + '%';
snowflake.style.animationDuration = Math.random() * 3 + 2 + 's';
snowflake.style.fontSize = Math.random() * 60 + 10 + 'px';
snowflake.style.opacity = Math.random() * 0.5 + 0.5;
const snowflakes = ['❄', '❅', '❆', '✵', '✶', '✷', '✸'];
snowflake.innerHTML = snowflakes[Math.floor(Math.random() * snowflakes.length)];
snowflake.addEventListener('animationend', () => {
snowflake.remove();
});
document.body.appendChild(snowflake);
}
setInterval(createSnowflake, 200);
document.body.addEventListener('click', () => {
window.open(CHEERLIGHTS_URL, '_blank');
});
</script>
</body>
</html>