顶部导航栏隐藏

This commit is contained in:
tangly1024
2022-02-08 09:54:19 +08:00
parent 39aacbb9c9
commit 0fa612a9f3
2 changed files with 6 additions and 1 deletions

View File

@@ -28,6 +28,7 @@ export default function HeaderArticle ({ post }) {
}
}
useEffect(() => {
scrollTrigger()
window.addEventListener('scroll', scrollTrigger)
return () => {
window.removeEventListener('scroll', scrollTrigger)
@@ -36,6 +37,7 @@ export default function HeaderArticle ({ post }) {
return (
<div
id="header"
className="w-full h-96 relative md:flex-shrink-0 overflow-hidden bg-cover bg-center bg-no-repeat"
style={{ backgroundImage: headerImage }}
>

View File

@@ -27,7 +27,10 @@ const TopNav = ({ tags, currentTag, categories, currentCategory, postCount }) =>
const scrollTrigger = throttle(() => {
const scrollS = window.scrollY
const nav = document.querySelector('#sticky-nav')
if (scrollS >= windowTop && scrollS > 20) {
const header = document.querySelector('#header')
const showNav = (scrollS > 10 && scrollS >= windowTop) || (header && scrollS < 5) // 非首页无大图时影藏顶部 滚动条置顶时隐藏
if (!showNav) {
nav && nav.classList.replace('top-0', '-top-16')
windowTop = scrollS
} else {