-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
53 lines (47 loc) · 1.86 KB
/
script.js
File metadata and controls
53 lines (47 loc) · 1.86 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
50
51
52
53
const sideMenu = document.querySelector('#sideMenu');
const navBar = document.querySelector('nav');
const navLink = document.querySelector('nav ul');
function openMenu() {
sideMenu.style.transform = 'translateX(-16rem)';
}
function closeMenu() {
sideMenu.style.transform = 'translateX(16rem)';
}
window.addEventListener('scroll', () => {
if (window.scrollY > 50) {
navBar.classList.add('bg-white', 'bg-opacity-90', 'backdrop-blur-lg',
'shadow-lg', 'dark:bg-[#11001F]', 'dark:shadow-white/20');
navLink.classList.remove('bg-white', 'shadow-sm', 'bg-opacity-90',
'bg-opacity-50','dark:border', 'dark:border-white/50',
'dark:bg-transparent');
} else {
navBar.classList.remove('bg-white', 'bg-opacity-50', 'backdrop-blur-lg',
'shadow-lg', 'dark:shadow-white/20');
navLink.classList.add('bg-white', 'shadow-sm', 'bg-opacity-50',
'bg-opacity-50','dark:border', 'dark:border-white/50',
'dark:bg-transparent');
}
})
// This runs when the page loads: sets the correct theme
(function () {
const html = document.documentElement;
const storedTheme = localStorage.getItem("theme");
const systemPrefersDark = window.matchMedia("(prefers-color-scheme: dark)").matches;
if (storedTheme === "dark" || (!storedTheme && systemPrefersDark)) {
html.classList.add("dark");
} else {
html.classList.remove("dark");
}
})();
// This toggles the theme when you click the moon button
function toggleTheme() {
const html = document.documentElement;
const currentTheme = localStorage.getItem("theme");
if (currentTheme === "dark") {
html.classList.remove("dark");
localStorage.setItem("theme", "light");
} else {
html.classList.add("dark");
localStorage.setItem("theme", "dark");
}
}