x
This commit is contained in:
1 parent
716bb98b50
commit
cb51c0faeb
11 files changed
+127
-30
No files matched your search
@@ -86,20 +86,42 @@ export default function Navbar({ topOffsetClassName = 'top-0' }: NavbarProps) {
|
||||
|
||||
// Keep --navbar-bottom in sync so the fixed mega-menu dropdown sits flush below the navbar
|
||||
useEffect(() => {
|
||||
let animationFrameId: number;
|
||||
const navElement = navRef.current;
|
||||
|
||||
const updateNavBottom = () => {
|
||||
if (navRef.current) {
|
||||
const bottom = navRef.current.getBoundingClientRect().bottom
|
||||
if (navElement) {
|
||||
const bottom = navElement.getBoundingClientRect().bottom
|
||||
document.documentElement.style.setProperty('--navbar-bottom', `${bottom}px`)
|
||||
}
|
||||
}
|
||||
|
||||
updateNavBottom()
|
||||
|
||||
window.addEventListener('scroll', updateNavBottom, { passive: true })
|
||||
window.addEventListener('resize', updateNavBottom)
|
||||
|
||||
const observer = new ResizeObserver(() => {
|
||||
cancelAnimationFrame(animationFrameId);
|
||||
animationFrameId = requestAnimationFrame(updateNavBottom);
|
||||
});
|
||||
|
||||
if (navElement) {
|
||||
observer.observe(navElement);
|
||||
navElement.addEventListener('transitionend', updateNavBottom);
|
||||
}
|
||||
observer.observe(document.body);
|
||||
|
||||
return () => {
|
||||
window.removeEventListener('scroll', updateNavBottom)
|
||||
window.removeEventListener('resize', updateNavBottom)
|
||||
observer.disconnect()
|
||||
if (navElement) {
|
||||
navElement.removeEventListener('transitionend', updateNavBottom);
|
||||
}
|
||||
cancelAnimationFrame(animationFrameId);
|
||||
}
|
||||
}, [])
|
||||
}, [topOffsetClassName])
|
||||
|
||||
useEffect(() => { setMobileOpen(false) }, [navigate])
|
||||
useEffect(() => {
|
||||
|
||||
Reference in new issue
Block a user