-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
32 lines (29 loc) · 996 Bytes
/
index.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
#codestarts
const toggle = document.getElementById('toggle');
const header = document.getElementById('header');
const navbar = document.getElementById('navbar');
const container = document.getElementById('home');
const activePage = window.location.pathname;
const links = document.querySelectorAll('.nav-bar ul li a');
toggle.onclick = function(active){
toggle.classList.toggle('active');
navbar.classList.toggle('active');
container.classList.toggle('active');
}
document.onclick = function(e){
if(e.target.id !== 'navbar'&& e.target.id !== 'toggle' && e.target.id != 'home'){
toggle.classList.remove('active');
navbar.classList.remove('active');
container.classList.remove('active');
}
}
if (links.length) {
links.forEach((link) => {
link.addEventListener('click', (e) => {
links.forEach((link) => {
link.classList.remove('active');
});
link.classList.add('active');
});
});
}