reverse header observer fuckery

This commit is contained in:
elisejakob
2024-07-07 14:02:42 +02:00
parent 53f8d03f27
commit aa914f4e6f
3 changed files with 11 additions and 16 deletions

View File

@ -8,7 +8,7 @@ import Icon from "../general/Icon";
import { useInView } from "react-intersection-observer"; import { useInView } from "react-intersection-observer";
export const Header = () => { export const Header = () => {
const { ref: observer, inView: isScrolled } = useInView({ const { ref: observer, inView: isInView } = useInView({
triggerOnce: false, triggerOnce: false,
}); });
@ -36,11 +36,14 @@ export const Header = () => {
useEffect(() => { useEffect(() => {
if (showMenu) { if (showMenu) {
document.body.style.overflow = "hidden"; const scrollY = window.scrollY;
document.body.style.height = "100vh"; document.body.style.position = "fixed";
document.body.style.top = `-${scrollY}px`;
} else { } else {
document.body.style.overflow = ""; const scrollY = parseInt(document.body.style.top || "0") * -1;
document.body.style.height = ""; document.body.style.position = "";
document.body.style.top = "";
window.scrollTo(0, scrollY);
} }
}, [showMenu]); }, [showMenu]);
@ -60,7 +63,7 @@ export const Header = () => {
<header <header
className={styles.header} className={styles.header}
data-show={showMenu} data-show={showMenu}
data-small={isScrolled} data-small={!isInView}
ref={siteMenu} ref={siteMenu}
> >
<Link href="/" aria-label="Hjem"> <Link href="/" aria-label="Hjem">
@ -176,7 +179,7 @@ export const Header = () => {
</nav> </nav>
<div className={styles.headerBar} aria-hidden> <div className={styles.headerBar} aria-hidden>
<Link href="/" aria-label="Hjem"> <Link href="/" aria-label="Hjem">
{isScrolled ? <LogoIcon face="right" /> : <Logo />} {!isInView ? <LogoIcon face="right" /> : <Logo />}
</Link> </Link>
<nav className={styles.siteMenu} ref={siteMenu}> <nav className={styles.siteMenu} ref={siteMenu}>
<ul className={styles.mainMenu}> <ul className={styles.mainMenu}>

View File

@ -211,6 +211,5 @@
// observer to trigger small menu // observer to trigger small menu
.observer { .observer {
position: absolute; position: absolute;
top: calc(100vh + 8rem); top: 8rem;
height: 100%;
} }

View File

@ -26,13 +26,6 @@ body {
line-height: 1.5; line-height: 1.5;
position: relative; position: relative;
@media (max-width: 1000px) {
&.hideScroll {
overflow: hidden;
height: 100vh;
}
}
} }
.site-main { .site-main {