fix img src path, add theme toggle button
All checks were successful
/ build (push) Successful in 10s
All checks were successful
/ build (push) Successful in 10s
This commit is contained in:
parent
d4ec541814
commit
f3b5be3c50
10 changed files with 181 additions and 126 deletions
|
|
@ -1,3 +1,27 @@
|
|||
document.querySelector('nav > button').addEventListener('click', (e) => {
|
||||
document.querySelector('nav').classList.toggle('visible');
|
||||
})
|
||||
})
|
||||
|
||||
function applyTheme(theme){
|
||||
const html = document.querySelector('html')
|
||||
document.cookie = `theme=${theme}; expires=; SameSite=Strict; Secure`
|
||||
html.classList.remove('dark', 'light')
|
||||
html.classList.add(theme)
|
||||
}
|
||||
|
||||
document.querySelectorAll('.toggleTheme').forEach(
|
||||
element => element.addEventListener('click', (e) => {
|
||||
const newTheme = element.dataset.theme;
|
||||
applyTheme(newTheme);
|
||||
}
|
||||
)
|
||||
);
|
||||
|
||||
const themeFromCookie = document.cookie
|
||||
.split("; ")
|
||||
.find((row) => row.startsWith("theme="))
|
||||
?.split("=")[1];
|
||||
|
||||
if (themeFromCookie) {
|
||||
applyTheme(themeFromCookie)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue