-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
29 lines (25 loc) · 806 Bytes
/
script.js
File metadata and controls
29 lines (25 loc) · 806 Bytes
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
const colorScheme = window.matchMedia("(prefers-color-scheme: dark)");
const html = document.documentElement;
let deg = 0;
// Animate page border with rotating linear background
function animateBorder() {
deg >= 360 ? deg = 0 : deg++; // Future Proofing :)
html.style.background = `background linear-gradient(${deg}deg, #ff6600, #029afe)`;
setTimeout(() => {
requestAnimationFrame(animateBorder);
}, 1000 / 48); // 48fps
}
animateBorder();
// Detect and set prefered color scheme
if (colorScheme.matches) {
html.setAttribute("data-theme", "dark");
} else {
html.setAttribute("data-theme", "light");
}
colorScheme.addEventListener("change", (event) => {
if (event.matches) {
html.setAttribute("data-theme", "dark");
} else {
html.setAttribute("data-theme", "light");
}
});