blob: 280fbdb467070790416de1f0e8055727665c39c6 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
import Navbar from "./navbar";
import Footer from "./footer";
import { useEffect, useState } from "react";
function Layout(props) {
const [isAtTop, setIsAtTop] = useState(true);
const [isScrollingDown, setIsScrollingDown] = useState(false);
useEffect(() => {
const handleScroll = () => {
const scrollY = window.scrollY;
const bodyHeight = document.body.offsetHeight;
const windowHeight = window.innerHeight;
const scrollPercent = (scrollY / (bodyHeight - windowHeight)) * 100;
if (scrollPercent <= 20) {
setIsAtTop(true);
setIsScrollingDown(false);
} else if (scrollY > lastScrollY) {
setIsAtTop(false);
setIsScrollingDown(true);
} else {
setIsAtTop(false);
setIsScrollingDown(false);
}
lastScrollY = scrollY;
};
let lastScrollY = window.scrollY;
window.addEventListener("scroll", handleScroll);
return () => {
window.removeEventListener("scroll", handleScroll);
};
}, []);
return (
<>
<main
className={`flex h-auto bg-[#121212] text-white flex-col ${props.className}`}
>
{/* PC/Tablet */}
<Navbar
className={`absolute z-50 hidden w-full duration-500 md:fixed md:top-0 md:block md:transition-all ${
isAtTop
? `px-2 pt-2 transition-all duration-1000 ${props.navTop}`
: isScrollingDown
? "md:h-16 md:translate-y-[-100%] md:shadow-sm md:bg-[#0c0d10] "
: "md:h-16 md:translate-y-0 md:shadow-sm md:bg-[#0c0d10]"
}`}
/>
{/* Mobile */}
<Navbar
className={`absolute z-50 w-full duration-300 md:fixed md:top-0 md:hidden md:transition-all`}
/>
<div className="grid items-center justify-center">{props.children}</div>
<Footer />
</main>
</>
);
}
export default Layout;
|