make nav clickable

This commit is contained in:
sakrecoer 2026-08-16 15:15:41 +02:00
parent 3daecd6eea
commit 1c35e99ed2

View file

@ -933,20 +933,25 @@ document.addEventListener('DOMContentLoaded', function() {
}); });
}); });
// Smooth scrolling for navigation links (both main nav and sticky nav) // Smooth scrolling for navigation links (only for # anchors)
document.querySelectorAll('nav a').forEach(link => { document.querySelectorAll('nav a').forEach(link => {
link.addEventListener('click', function(e) { link.addEventListener('click', function(e) {
e.preventDefault(); const href = this.getAttribute('href');
const targetId = this.getAttribute('href'); // Only intercept if it's a # anchor link
const targetElement = document.querySelector(targetId); if (href && href.startsWith('#')) {
if (targetElement) { e.preventDefault();
const navHeight = stickyNav.offsetHeight; const targetId = href;
const targetPosition = targetElement.getBoundingClientRect().top + window.pageYOffset - navHeight - 20; const targetElement = document.querySelector(targetId);
window.scrollTo({ if (targetElement) {
top: targetPosition, const navHeight = stickyNav.offsetHeight;
behavior: 'smooth' const targetPosition = targetElement.getBoundingClientRect().top + window.pageYOffset - navHeight - 20;
}); window.scrollTo({
top: targetPosition,
behavior: 'smooth'
});
}
} }
// If it's a regular link (like /playlists/), let it navigate normally
}); });
}); });