-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathscript.js
64 lines (51 loc) · 1.66 KB
/
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
let toggleBtn = document.getElementById('toggle-btn');
let body = document.body;
let darkMode = localStorage.getItem('dark-mode');
const enableDarkMode = () =>{
toggleBtn.classList.replace('fa-sun', 'fa-moon');
body.classList.add('dark');
localStorage.setItem('dark-mode', 'enabled');
}
const disableDarkMode = () =>{
toggleBtn.classList.replace('fa-moon', 'fa-sun');
body.classList.remove('dark');
localStorage.setItem('dark-mode', 'disabled');
}
if(darkMode === 'enabled'){
enableDarkMode();
}
toggleBtn.onclick = (e) =>{
darkMode = localStorage.getItem('dark-mode');
if(darkMode === 'disabled'){
enableDarkMode();
}else{
disableDarkMode();
}
}
let profile = document.querySelector('.header .flex .profile');
document.querySelector('#user-btn').onclick = () =>{
profile.classList.toggle('active');
search.classList.remove('active');
}
let search = document.querySelector('.header .flex .search-form');
document.querySelector('#search-btn').onclick = () =>{
search.classList.toggle('active');
profile.classList.remove('active');
}
let sideBar = document.querySelector('.side-bar');
document.querySelector('#menu-btn').onclick = () =>{
sideBar.classList.toggle('active');
body.classList.toggle('active');
}
document.querySelector('#close-btn').onclick = () =>{
sideBar.classList.remove('active');
body.classList.remove('active');
}
window.onscroll = () =>{
profile.classList.remove('active');
search.classList.remove('active');
if(window.innerWidth < 1200){
sideBar.classList.remove('active');
body.classList.remove('active');
}
}