Add sticky header + autohide.

This commit is contained in:
Benjamin A. Shelton 2026-12-02 18:25:32 -07:00
commit 7da90092ad
Signed by: zancarius
GPG key ID: 8BD42DBD6C337E01
2 changed files with 30 additions and 2 deletions

View file

@ -8,7 +8,7 @@ import { urlfrag } from '../utils/path';
const base = import.meta.env.BASE_URL;
---
<header>
<header id="header">
<div class="justify-self-start">
<Menu />
</div>
@ -20,4 +20,30 @@ const base = import.meta.env.BASE_URL;
<Icon name="eye" desc="Disable Accessibility Options" />
</a>
</div>
</header>
</header>
<script>
const header = document.getElementById('header');
const DWELL_TIME = 1500;
let lastpos = window.scrollY;
let hideTimeout: NodeJS.Timeout;
function onScroll() {
const currentpos = window.scrollY;
clearTimeout(hideTimeout);
if (currentpos <= 100 || currentpos < lastpos) {
header?.classList.remove('-translate-y-full');
console.log("<", currentpos, lastpos);
} else if (currentpos > lastpos) {
header?.classList.remove('-translate-y-full');
hideTimeout = setTimeout(() => {
//if (window.scrollY > 100) {
header?.classList.add('-translate-y-full');
//}
}, DWELL_TIME);
}
lastpos = currentpos;
}
header?.addEventListener('mouseenter', () => clearTimeout(hideTimeout));
header?.addEventListener('focusin', () => clearTimeout(hideTimeout));
window.addEventListener('scroll', onScroll, {passive: true});
</script>

View file

@ -168,6 +168,8 @@ body {
}
html > body > header {
@apply sticky top-0 backdrop-blur w-full z-50;
@apply transition-transform duration-300 ease-in-out;
@apply bg-sunday-theme p-4 text-white text-3xl lg:text-4xl grid grid-cols-[1fr_auto_1fr] items-center gap-4;
}