Sync: enhance header behavior for light hero backgrounds with dynamic class toggling

This commit is contained in:
Matt Batchelder
2026-02-21 14:42:45 -05:00
parent 8926a9b071
commit a89f9067e2
2 changed files with 19 additions and 4 deletions

View File

@@ -17,6 +17,19 @@ document.addEventListener('DOMContentLoaded', () => {
window.addEventListener('scroll', () => {
header.classList.toggle('scrolled', window.scrollY > 40);
}, { passive: true });
/* Detect whether the hero beneath the header has a light background.
.hero (homepage) is white in light mode; .page-hero stays dark.
Re-evaluate when the theme toggle changes data-theme. */
function updateHeroContrast() {
const isLight = document.documentElement.getAttribute('data-theme') !== 'dark';
const hasLightHero = isLight && document.querySelector('.hero') && !document.querySelector('.page-hero');
header.classList.toggle('over-light-hero', !!hasLightHero);
}
updateHeroContrast();
new MutationObserver(updateHeroContrast).observe(document.documentElement, {
attributes: true, attributeFilter: ['data-theme']
});
}
/* ── Mobile nav toggle ──────────────────────────────────── */