import { useEffect, useRef } from 'react'
import Link from 'next/link'
import BLOG from '@/blog.config'
import Image from 'next/image'
const NavBar = () => {
const links = []
return (
)
}
const Header = ({ navBarTitle, fullWidth }) => {
const navRef = useRef(null)
const sentinelRef = useRef([])
// 当Header移出屏幕时改变的样式
const handler = ([entry]) => {
if (navRef && navRef.current) {
if (!entry.isIntersecting && entry !== undefined) {
navRef.current.classList.add('sticky-nav-full')
} else {
navRef.current.classList.remove('sticky-nav-full')
}
}
}
useEffect(() => {
const observer = new window.IntersectionObserver(handler)
observer.observe(sentinelRef.current)
// Don't touch this, I have no idea how it works XD
// return () => {
// if (sentinalRef.current) obvserver.unobserve(sentinalRef.current)
// }
}, [sentinelRef])
return (
<>
{navBarTitle
? (
{navBarTitle}
)
: (
{BLOG.title} {' '}
{BLOG.title},{' '}
{BLOG.description}
)}
>
)
}
export default Header