-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy paththeme.js
20 lines (17 loc) · 864 Bytes
/
theme.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
document.addEventListener("DOMContentLoaded", () => {
const switchTheme = () => {
document.body.classList.toggle("light-theme");
const themeButton = document.querySelector(".theme-change-button")
themeButton.src = (document.body.classList.contains("light-theme")) ? "images/toggle_light.png" : "images/toggle_dark.png" ;
themeButton.style.borderColor = (document.body.classList.contains("light-theme")) ? "black" : "White" ;
}
const themeSwitcher = document.querySelector(".theme-change-button");
themeSwitcher.addEventListener("click" , switchTheme);
// const themePreferenceDark = window.matchMedia("prefers-color-scheme: dark"); // try light instead
// console.log(themePreferenceDark.matches);
// if(themePreferenceDark){
// switchTheme();
// }
// else{
// }
})