24 lines
750 B
JavaScript
24 lines
750 B
JavaScript
// Highlight active nav link on scroll
|
|
const sections = document.querySelectorAll('section[id]');
|
|
const links = document.querySelectorAll('nav a');
|
|
|
|
const observer = new IntersectionObserver(entries => {
|
|
entries.forEach(e => {
|
|
if (e.isIntersecting) {
|
|
links.forEach(l => l.classList.remove('active'));
|
|
const active = document.querySelector(`nav a[href="#${e.target.id}"]`);
|
|
if (active) active.classList.add('active');
|
|
}
|
|
});
|
|
}, { threshold: 0.3 });
|
|
|
|
sections.forEach(s => observer.observe(s));
|
|
|
|
// Hide the profile photo if it fails to load
|
|
const profilePhoto = document.querySelector('.profile-photo');
|
|
if (profilePhoto) {
|
|
profilePhoto.addEventListener('error', () => {
|
|
profilePhoto.style.display = 'none';
|
|
});
|
|
}
|