-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathscript.js
30 lines (26 loc) · 949 Bytes
/
script.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
const themeToggleBtn = document.getElementById('theme-toggle-btn');
const themeOptions = document.getElementById('theme-options');
const body = document.body;
themeToggleBtn.addEventListener('click', toggleThemeOptions);
function toggleThemeOptions() {
themeOptions.classList.toggle('show');
}
const themeOptionsList = themeOptions.getElementsByClassName('theme-option');
for (let i = 0; i < themeOptionsList.length; i++) {
themeOptionsList[i].addEventListener('click', changeTheme);
}
function changeTheme() {
const selectedTheme = this.id;
body.className = selectedTheme;
}
function changeTheme() {
const selectedTheme = this.id;
body.className = selectedTheme;
localStorage.setItem('selectedTheme', selectedTheme);
}
window.addEventListener('DOMContentLoaded', function() {
const selectedTheme = localStorage.getItem('selectedTheme');
if (selectedTheme) {
body.className = selectedTheme;
}
});