-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscripts.js
More file actions
30 lines (25 loc) · 905 Bytes
/
scripts.js
File metadata and controls
30 lines (25 loc) · 905 Bytes
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
document.addEventListener("DOMContentLoaded", function() {
const menu = document.querySelector('#dropdown-menu');
const menuLinks = document.querySelector('.navbar__menu');
menu.addEventListener('click', function() {
menu.classList.toggle('is-active');
menuLinks.classList.toggle('active');
});
const path = window.location.pathname;
const page = path.substring(path.lastIndexOf('/') + 1);
const pageMap = {
'index.html': 'home-link',
'services.html': 'services-link',
'about_me.html': 'about-me-link',
}
let activeLinkId;
if (page === '' || page === 'index.html') {
activeLinkId = 'home-link';
} else {
activeLinkId = pageMap[page];
}
if (activeLinkId) {
const activeLink = document.getElementById(activeLinkId);
if (activeLink) activeLink.classList.add('active');
}
});