34866-vm/assets/js/main.js
2025-10-10 23:34:21 +00:00

35 lines
1.1 KiB
JavaScript

document.addEventListener('DOMContentLoaded', function() {
const navLinks = document.querySelectorAll('.sidebar nav a');
navLinks.forEach(link => {
link.addEventListener('click', function(e) {
e.preventDefault();
document.querySelector(this.getAttribute('href')).scrollIntoView({
behavior: 'smooth'
});
navLinks.forEach(nav => nav.classList.remove('active'));
this.classList.add('active');
});
});
// Set active link on scroll
const sections = document.querySelectorAll('section');
window.addEventListener('scroll', () => {
let current = '';
sections.forEach(section => {
const sectionTop = section.offsetTop;
if (pageYOffset >= sectionTop - 60) {
current = section.getAttribute('id');
}
});
navLinks.forEach(link => {
link.classList.remove('active');
if (link.getAttribute('href').includes(current)) {
link.classList.add('active');
}
});
});
});