-
Notifications
You must be signed in to change notification settings - Fork 181
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #170 from lakshmirajvagu/main
modified light theme
- Loading branch information
Showing
2 changed files
with
60 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,30 @@ | ||
const checkbox = document.getElementById('checkbox') | ||
const modeLabel = document.getElementById('mode-label') | ||
const checkbox = document.getElementById('checkbox'); | ||
const modeLabel = document.getElementById('mode-label'); | ||
const body = document.body; // Selecting the body to change the background image and text color | ||
|
||
// Check if dark mode is already enabled | ||
if (localStorage.getItem('theme') === 'dark') { | ||
document.documentElement.setAttribute('data-theme', 'dark') | ||
checkbox.checked = true | ||
modeLabel.textContent = 'Dark Mode' | ||
document.documentElement.setAttribute('data-theme', 'dark'); | ||
checkbox.checked = true; | ||
modeLabel.textContent = 'Dark Mode'; | ||
body.style.backgroundImage = "url('path-to-dark-theme-image.jpg')"; // Set dark theme background image | ||
} else { | ||
document.documentElement.setAttribute('data-theme', 'light'); | ||
modeLabel.textContent = 'Light Mode'; | ||
body.style.backgroundImage = "url('path-to-light-theme-image.jpg')"; // Set light theme background image | ||
} | ||
|
||
// Add event listener for toggle switch | ||
checkbox.addEventListener('change', () => { | ||
if (checkbox.checked) { | ||
document.documentElement.setAttribute('data-theme', 'dark') | ||
localStorage.setItem('theme', 'dark') | ||
modeLabel.textContent = 'Dark Mode' | ||
document.documentElement.setAttribute('data-theme', 'dark'); | ||
localStorage.setItem('theme', 'dark'); | ||
modeLabel.textContent = 'Dark Mode'; | ||
body.style.backgroundImage = "url('path-to-dark-theme-image.jpg')"; // Set dark theme background image | ||
} else { | ||
document.documentElement.setAttribute('data-theme', 'light') | ||
localStorage.setItem('theme', 'light') | ||
modeLabel.textContent = 'Light Mode' | ||
document.documentElement.setAttribute('data-theme', 'light'); | ||
localStorage.setItem('theme', 'light'); | ||
modeLabel.textContent = 'Light Mode'; | ||
body.style.backgroundImage = "url('path-to-light-theme-image.jpg')"; // Set light theme background image | ||
} | ||
}) | ||
}); |