-
-
Notifications
You must be signed in to change notification settings - Fork 260
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 #85 from meghanakn473/main
dark mode feature (issue#13)
- Loading branch information
Showing
3 changed files
with
44 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,10 @@ | |
|
||
<link rel="stylesheet" href="style.css"> | ||
<style> | ||
<label for="dark-mode-toggle"> | ||
<input type="checkbox" id="dark-mode-toggle" /> | ||
Toggle Dark Mode | ||
</label> | ||
|
||
/* Features Section */ | ||
.features { | ||
|
@@ -398,4 +402,4 @@ <h3>Connect With Us</h3> | |
<script src="https://cdn.jsdelivr.net/npm/@popperjs/[email protected]/dist/umd/popper.min.js"></script> | ||
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script> | ||
</body> | ||
</html> | ||
</html> |
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 |
---|---|---|
@@ -0,0 +1,19 @@ | ||
const toggleSwitch = document.getElementById('dark-mode-toggle'); | ||
|
||
// Check for saved user preference in local storage | ||
const currentTheme = localStorage.getItem('theme') ? localStorage.getItem('theme') : null; | ||
|
||
if (currentTheme) { | ||
document.body.classList.toggle('dark-mode', currentTheme === 'dark'); | ||
toggleSwitch.checked = currentTheme === 'dark'; | ||
} | ||
|
||
toggleSwitch.addEventListener('change', () => { | ||
document.body.classList.toggle('dark-mode'); | ||
// Save preference to local storage | ||
if (document.body.classList.contains('dark-mode')) { | ||
localStorage.setItem('theme', 'dark'); | ||
} else { | ||
localStorage.setItem('theme', 'light'); | ||
} | ||
}); |
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