mirror of
https://github.com/d0zingcat/NotionNext.git
synced 2026-05-14 07:26:52 +00:00
feature:
TopNav监听滚动
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
import { useGlobal } from '@/lib/global'
|
||||
import { faArrowDown } from '@fortawesome/free-solid-svg-icons'
|
||||
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
|
||||
import { useEffect, useState } from 'react'
|
||||
import throttle from 'lodash.throttle'
|
||||
import { useCallback, useEffect, useState } from 'react'
|
||||
import Typed from 'typed.js'
|
||||
|
||||
/**
|
||||
@@ -19,6 +21,29 @@ export default function Header () {
|
||||
const scrollToCenter = () => {
|
||||
document.getElementById('wrapper').scrollIntoView({ behavior: 'smooth' })
|
||||
}
|
||||
|
||||
const { theme } = useGlobal()
|
||||
// 监听滚动自动分页加载
|
||||
const scrollTrigger = useCallback(throttle(() => {
|
||||
if (theme !== 'dark') {
|
||||
const stickyNavElement = document.getElementById('sticky-nav')
|
||||
if (window.scrollY < window.innerHeight) {
|
||||
stickyNavElement.classList.add('dark')
|
||||
} else {
|
||||
stickyNavElement.classList.remove('dark')
|
||||
}
|
||||
}
|
||||
}, 500))
|
||||
|
||||
// 监听滚动
|
||||
useEffect(() => {
|
||||
scrollTrigger()
|
||||
window.addEventListener('scroll', scrollTrigger)
|
||||
return () => {
|
||||
window.removeEventListener('scroll', scrollTrigger)
|
||||
}
|
||||
})
|
||||
|
||||
return <div className='h-screen w-full'>
|
||||
<div className='absolute z-10 flex h-screen items-center justify-center w-full'>
|
||||
<div id="typed-strings">
|
||||
|
||||
@@ -14,7 +14,7 @@ const TopNav = ({ tags, currentTag, post, posts, categories, currentCategory })
|
||||
<SideBarDrawer post={post} currentTag={currentTag} cRef={drawer} tags={tags} posts={posts} categories={categories} currentCategory={currentCategory}/>
|
||||
|
||||
{/* 导航栏 */}
|
||||
<div id='sticky-nav' className='dark flex fixed md:relative w-full top-0 z-20 transform duration-500'>
|
||||
<div id='sticky-nav' className='flex fixed md:relative w-full top-0 z-20 transform duration-500'>
|
||||
<div className='w-full flex justify-between items-center p-4 glassmorphism'>
|
||||
{/* 左侧LOGO 标题 */}
|
||||
<div className='flex flex-none flex-grow-0'>
|
||||
|
||||
Reference in New Issue
Block a user