-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
26 lines (23 loc) · 980 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
// Function to set the active link based on the current URL
function setActiveNavLink() {
// Get the current page's URL
const currentUrl = window.location.pathname;
// Define the navigation links and their corresponding URLs
const navLinks = [
{ id: 'nav-homepage', url: '/homepage.html' },
{ id: 'nav-portfolio', url: '/portfoliopage.html' },
{ id: 'nav-resume', url: '/resumepage.html' },
{ id: 'nav-contact', url: '/contactpage.html' },
];
// Loop through the nav links and set the active class if the URL matches
navLinks.forEach(link => {
const navElement = document.getElementById(link.id);
if (navElement && currentUrl.endsWith(link.url)) {
navElement.classList.add('active');
} else {
navElement.classList.remove('active');
}
});
}
// Call the function to set the active link on page load
window.onload = setActiveNavLink;