notes/src/components/Header.astro

60 lines
1.8 KiB
Text
Raw Normal View History

2026-06-05 14:31:12 -06:00
---
import "../styles/global.css";
2026-11-24 14:30:44 -07:00
import Menu from './Menu.astro';
2026-06-05 14:31:12 -06:00
import { Icon } from 'astro-icon/components';
2026-07-09 19:33:16 -06:00
import { urlfrag } from '../utils/path';
2026-06-05 14:31:12 -06:00
const base = import.meta.env.BASE_URL;
---
2026-12-02 18:25:32 -07:00
<header id="header">
<div class="justify-self-start">
2026-11-24 14:30:44 -07:00
<Menu />
</div>
<h1 class="text-center">
2026-07-09 15:39:55 -06:00
<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>
2026-12-02 18:25:32 -07:00
</header>
<script>
const header = document.getElementById('header');
const DWELL_TIME = 1500;
let lastpos = window.scrollY;
let hideTimeout: NodeJS.Timeout;
let hideScroll = false;
2026-12-02 18:25:32 -07:00
function onScroll() {
const currentpos = window.scrollY;
clearTimeout(hideTimeout);
if (hideScroll) {
header?.classList.add('-translate-y-full');
hideScroll = false;
return;
}
2026-12-02 18:25:32 -07:00
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;
}
document.querySelectorAll('sup > a').forEach((el) => {
el.addEventListener('click', () => {
hideScroll = true;
}, {passive: true});
});
2026-12-02 18:25:32 -07:00
header?.addEventListener('mouseenter', () => clearTimeout(hideTimeout));
header?.addEventListener('focusin', () => clearTimeout(hideTimeout));
window.addEventListener('scroll', onScroll, {passive: true});
</script>