sundays/src/components/Header.astro

49 lines
No EOL
1.5 KiB
Text

---
import "../styles/global.css";
import Menu from './Menu.astro';
import { Icon } from 'astro-icon/components';
import { urlfrag } from '../utils/path';
const base = import.meta.env.BASE_URL;
---
<header id="header">
<div class="justify-self-start">
<Menu />
</div>
<h1 class="text-center">
<a href={base}><b>Just Us</b> Notes</a>
</h1>
<div class="justify-self-end flex items-center gap-2">
<a id="af-toggle" class="hidden">
<Icon name="eye" desc="Disable Accessibility Options" />
</a>
</div>
</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>