Add sticky header + autohide.
This commit is contained in:
parent
4d8f83a63c
commit
7da90092ad
2 changed files with 30 additions and 2 deletions
|
|
@ -8,7 +8,7 @@ import { urlfrag } from '../utils/path';
|
||||||
|
|
||||||
const base = import.meta.env.BASE_URL;
|
const base = import.meta.env.BASE_URL;
|
||||||
---
|
---
|
||||||
<header>
|
<header id="header">
|
||||||
<div class="justify-self-start">
|
<div class="justify-self-start">
|
||||||
<Menu />
|
<Menu />
|
||||||
</div>
|
</div>
|
||||||
|
|
@ -21,3 +21,29 @@ const base = import.meta.env.BASE_URL;
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</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>
|
||||||
|
|
@ -168,6 +168,8 @@ body {
|
||||||
}
|
}
|
||||||
|
|
||||||
html > body > header {
|
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;
|
@apply bg-sunday-theme p-4 text-white text-3xl lg:text-4xl grid grid-cols-[1fr_auto_1fr] items-center gap-4;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue