patx/afterdarklabs
fix nav scroll awareness
Commit a95f7b5 · patx · 2026-07-07T00:29:51-04:00
Comments
No comments yet.
Diff
diff --git a/docs/index.html b/docs/index.html
index f198d1e..f2cbeba 100644
--- a/docs/index.html
+++ b/docs/index.html
@@ -443,16 +443,18 @@
(function () {
const activeClasses = ['text-[#ccff00]', 'font-semibold'];
const navLinks = Array.from(document.querySelectorAll('nav a[data-nav-link]'));
- const sections = [
- { id: 'hero', href: '#hero' },
- { id: 'process', href: '#process' },
- { id: 'services', href: '#services' },
- { id: 'work', href: '#work' },
- { id: 'questionnaire', href: '#questionnaire' },
- ];
if (!navLinks.length) return;
+ const linkedHrefs = Array.from(new Set(
+ navLinks
+ .map(link => link.getAttribute('href'))
+ .filter(href => href && href.startsWith('#'))
+ ));
+ const sections = Array.from(document.querySelectorAll('main section[id]'))
+ .map(element => ({ element, href: `#${element.id}` }))
+ .filter(section => linkedHrefs.includes(section.href));
+
function setActive(href) {
navLinks.forEach(link => {
const isActive = link.getAttribute('href') === href;
@@ -472,10 +474,7 @@
let currentHref = '';
for (const section of sections) {
- const element = document.getElementById(section.id);
- if (!element) continue;
-
- if (element.getBoundingClientRect().top <= offset) {
+ if (section.element.getBoundingClientRect().top <= offset) {
currentHref = section.href;
}
}