Files
pbakaus_impeccable/public/js/components/section-nav.js
T
Paul BakausandClaude Opus 4.6 8d1937d3c9 Homepage UX improvements from design critique
- Add floating bottom section nav (appears after hero, hides at footer)
- Fix hero split comparison to default 50/50 instead of 70/30
- Remove duplicate "Works with" badges from Install section
- Periodic table: restore compact elements, add inline hover tooltips
- Truncate command descriptions in Commands section for scannability
- Collapse older changelog entries behind "View older releases"
- Add GitHub star count (13.3k) next to repo link
- Fix meta theme-color to match light mode
- Reduce hero top padding, update section 03 subtitle
- Clean up footer: remove redundant tagline and anchor links
- Fix divider line accumulation in changelog and FAQ sections
- Center glass terminal vertically in viewport

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-24 19:22:12 -07:00

67 lines
1.7 KiB
JavaScript

/**
* Sticky Section Nav
* Shows/hides based on scroll position and highlights current section.
*/
export function initSectionNav() {
const nav = document.getElementById('section-nav');
if (!nav) return;
const items = nav.querySelectorAll('.section-nav-item');
const sectionIds = Array.from(items).map(item => item.dataset.section);
// Show/hide nav based on scroll position
const hero = document.getElementById('hero');
const footer = document.querySelector('.site-footer');
if (!hero) return;
let ticking = false;
function updateNav() {
const scrollY = window.scrollY;
const heroBottom = hero.offsetTop + hero.offsetHeight - 100;
const footerTop = footer ? footer.offsetTop : Infinity;
const viewportBottom = scrollY + window.innerHeight;
// Show nav after hero, hide when footer is visible
if (scrollY > heroBottom && viewportBottom < footerTop + 60) {
nav.classList.add('is-visible');
} else {
nav.classList.remove('is-visible');
}
// Find current section
let currentSection = null;
const viewportMiddle = scrollY + window.innerHeight * 0.4;
for (let i = sectionIds.length - 1; i >= 0; i--) {
const section = document.getElementById(sectionIds[i]);
if (section && section.offsetTop <= viewportMiddle) {
currentSection = sectionIds[i];
break;
}
}
// Update active state
items.forEach(item => {
if (item.dataset.section === currentSection) {
item.classList.add('is-active');
} else {
item.classList.remove('is-active');
}
});
ticking = false;
}
window.addEventListener('scroll', () => {
if (!ticking) {
requestAnimationFrame(updateNav);
ticking = true;
}
}, { passive: true });
// Initial check
updateNav();
}