|
|
|
|
|
|
|
document.addEventListener('DOMContentLoaded', () => { |
|
const currentLocation = window.location.pathname; |
|
const navLinks = document.querySelectorAll('nav a'); |
|
|
|
navLinks.forEach(link => { |
|
if (link.getAttribute('href') === currentLocation || |
|
(currentLocation.endsWith('/') && link.getAttribute('href') === '/index.html')) { |
|
link.classList.add('nav-active'); |
|
} |
|
}); |
|
}); |
|
|
|
|
|
function toggleMobileNav() { |
|
const nav = document.querySelector('nav ul'); |
|
nav.classList.toggle('mobile-nav-active'); |
|
} |
|
|
|
|
|
document.querySelectorAll('a[href^="#"]').forEach(anchor => { |
|
anchor.addEventListener('click', function(e) { |
|
e.preventDefault(); |
|
|
|
const targetId = this.getAttribute('href'); |
|
const targetElement = document.querySelector(targetId); |
|
|
|
if (targetElement) { |
|
window.scrollTo({ |
|
top: targetElement.offsetTop - 80, |
|
behavior: 'smooth' |
|
}); |
|
} |
|
}); |
|
}); |
|
|