-
Notifications
You must be signed in to change notification settings - Fork 0
/
crowdfund.js
54 lines (45 loc) · 1.7 KB
/
crowdfund.js
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
54
function toggleSideNav(x) {
const sidenav = document.getElementById("mySidenav");
sidenav.style.width = sidenav.style.width === "250px" ? "0" : "250px";
x.classList.toggle("change");
}
function closesideNav() {
document.getElementById("mySidenav").style.width = "0";
}
// Toggle between light and dark mode
function toggleTheme() {
document.body.classList.toggle("dark-mode");
}
// Function to apply the theme based on localStorage value
function applySavedTheme() {
const savedTheme = localStorage.getItem('theme');
if (savedTheme === 'dark') {
document.body.classList.add('dark-mode');
} else {
document.body.classList.remove('dark-mode');
}
}
// Wait until the DOM is fully loaded before running the script
document.addEventListener('DOMContentLoaded', function() {
// Function to apply the theme based on localStorage value
function applySavedTheme() {
const savedTheme = localStorage.getItem('theme');
if (savedTheme === 'dark') {
document.body.classList.add('dark-mode');
} else {
document.body.classList.remove('dark-mode');
}
}
// Call the function to apply theme when the page loads
applySavedTheme();
// Function to toggle theme and save the preference
window.toggleTheme = function() {
if (document.body.classList.contains('dark-mode')) {
document.body.classList.remove('dark-mode');
localStorage.setItem('theme', 'light'); // Save light theme to localStorage
} else {
document.body.classList.add('dark-mode');
localStorage.setItem('theme', 'dark'); // Save dark theme to localStorage
}
};
});