mirror of
https://github.com/d0zingcat/NotionNext.git
synced 2026-05-14 07:26:52 +00:00
feature:
调整Header,平滑滚动
This commit is contained in:
@@ -12,9 +12,14 @@ import Typed from 'typed.js'
|
||||
export default function Header () {
|
||||
const [typed, changeType] = useState()
|
||||
useEffect(() => {
|
||||
if (!typed) {
|
||||
if (!typed && window && document.getElementById('typed')) {
|
||||
changeType(new Typed('#typed', {
|
||||
stringsElement: '#typed-strings', typeSpeed: 200, showCursor: false
|
||||
strings: ['Hi,我是一个程序员', 'Hi,我是一个打工人', 'Hi,我是一个干饭人', '欢迎来到我的博客🎉'],
|
||||
typeSpeed: 200,
|
||||
backSpeed: 100,
|
||||
backDelay: 400,
|
||||
showCursor: true,
|
||||
smartBackspace: true
|
||||
}))
|
||||
}
|
||||
})
|
||||
@@ -23,8 +28,20 @@ export default function Header () {
|
||||
}
|
||||
|
||||
const { theme } = useGlobal()
|
||||
// 监听滚动自动分页加载
|
||||
// 监听滚动
|
||||
let windowTop = 0
|
||||
const scrollTrigger = useCallback(throttle(() => {
|
||||
if (window.scrollY > windowTop & window.scrollY < window.innerHeight) {
|
||||
scrollToCenter()
|
||||
}
|
||||
if (window.scrollY < windowTop & window.scrollY < window.innerHeight) {
|
||||
window.scroll({ top: 0, behavior: 'smooth' })
|
||||
}
|
||||
windowTop = window.scrollY
|
||||
updateTopNav()
|
||||
}, 500))
|
||||
|
||||
const updateTopNav = () => {
|
||||
if (theme !== 'dark') {
|
||||
const stickyNavElement = document.getElementById('sticky-nav')
|
||||
if (window.scrollY < window.innerHeight) {
|
||||
@@ -33,27 +50,26 @@ export default function Header () {
|
||||
stickyNavElement.classList.remove('dark')
|
||||
}
|
||||
}
|
||||
}, 500))
|
||||
}
|
||||
|
||||
// 监听滚动
|
||||
useEffect(() => {
|
||||
scrollTrigger()
|
||||
updateTopNav()
|
||||
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">
|
||||
<h2 className='text-xs text-white font-serif'>唐风集里,收卷波澜。</h2>
|
||||
</div>
|
||||
<div id="typed" className='text-4xl md:text-7xl text-center text-white font-serif'></div>
|
||||
return <header className='h-screen w-full'>
|
||||
|
||||
<div className='absolute z-10 flex h-screen items-center justify-center w-full text-4xl md:text-7xl text-white'>
|
||||
<div id="typed" className=' text-center font-serif'></div>
|
||||
<div onClick={scrollToCenter} className='cursor-pointer w-full text-center text-2xl animate-bounce absolute bottom-10 text-white'><FontAwesomeIcon icon={faArrowDown} /></div>
|
||||
</div>
|
||||
<div className='bg-black bg-cover bg-center h-screen md:-mt-14'
|
||||
style={{ backgroundImage: 'linear-gradient(rgba(0, 0, 0, 0.5), rgba(0,0,0,0.4), rgba(0, 0, 0, 0.5) ),url("https://pic2.zhimg.com/v2-9dfb9bd28656a13d7d57793c853dfb52_r.jpg")' }}>
|
||||
|
||||
<div className='bg-black bg-cover bg-center h-screen md:-mt-14 animate__fadeInRight animate_fadeIn'
|
||||
style={{ backgroundImage: 'linear-gradient(rgba(0, 0, 0, 0.5), rgba(0,0,0,0.4), rgba(0, 0, 0, 0.5) ),url("./bg_image.jpg")' }}>
|
||||
</div>
|
||||
</div>
|
||||
</header>
|
||||
}
|
||||
|
||||
@@ -34,7 +34,7 @@ const LatestPostsGroup = ({ posts, sliceCount = 5 }) => {
|
||||
<Link key={post.id} title={post.title} href={`${BLOG.path}/article/${post.slug}`} passHref>
|
||||
<a className={(selected ? 'text-white bg-blue-600 ' : 'text-gray-500 dark:text-gray-300 ') + ' my-1 px-5 flex font-light justify-between'}>
|
||||
<div className={ 'text-xs py-1.5 flex overflow-x-hidden whitespace-nowrap overflow-hidden ' +
|
||||
'hover:text-blue-500 dark:hover:text-blue-400 cursor-pointer hover:underline ' }>
|
||||
'hover:text-blue-500 dark:hover:text-blue-400 cursor-pointer hover:underline truncate' }>
|
||||
<FontAwesomeIcon icon={faFileAlt} className='mr-2'/>
|
||||
{post.title}
|
||||
</div>
|
||||
|
||||
@@ -74,7 +74,7 @@ const SideAreaRight = ({
|
||||
|
||||
<Analytics postCount={postCount}/>
|
||||
|
||||
<div className="sticky top-8">
|
||||
<div className="sticky top-14">
|
||||
{showToc && (
|
||||
<section className='pb-10 mb-5 rounded-xl shadow-md bg-white dark:bg-gray-800 hover:shadow-2xl duration-200'>
|
||||
<div className='border-b text-center text-2xl bg-white text-black rounded-t-xl dark:border-gray-700 dark:bg-gray-700 dark:text-white py-6 px-6'>
|
||||
@@ -124,7 +124,7 @@ const SideAreaRight = ({
|
||||
)}
|
||||
|
||||
{/* 分类 */}
|
||||
{post && categories && (
|
||||
{categories && (
|
||||
<section className='rounded-xl shadow-md py-4 mb-5 bg-white dark:bg-gray-800 hover:shadow-2xl duration-200'>
|
||||
<div className='text-sm px-5 mb-2 flex flex-nowrap justify-between font-light'>
|
||||
<div className='pb-1 text-gray-600 dark:text-gray-200'><FontAwesomeIcon icon={faThList} className='mr-2' />{locale.COMMON.CATEGORY}</div>
|
||||
|
||||
@@ -22,7 +22,7 @@ const TopNav = ({ tags, currentTag, post, posts, categories, currentCategory })
|
||||
alt={BLOG.title}
|
||||
layout='fill'
|
||||
loading='lazy'
|
||||
src='/avatar.svg'
|
||||
src='/favicon.svg'
|
||||
className='border-black'
|
||||
/></div>
|
||||
<Link href='/' passHref>
|
||||
|
||||
@@ -10,6 +10,8 @@ import { useGlobal } from '@/lib/global'
|
||||
import throttle from 'lodash.throttle'
|
||||
import PropTypes from 'prop-types'
|
||||
import React, { useCallback, useEffect, useRef } from 'react'
|
||||
import { useRouter } from 'next/router'
|
||||
import Header from '@/components/Header'
|
||||
/**
|
||||
* 基础布局 采用左右两侧布局,移动端使用顶部导航栏
|
||||
* @param children
|
||||
@@ -63,6 +65,7 @@ const BaseLayout = ({
|
||||
}, [])
|
||||
const { onLoading } = useGlobal()
|
||||
const targetRef = useRef(null)
|
||||
const router = useRouter()
|
||||
|
||||
return (<div>
|
||||
|
||||
@@ -71,9 +74,10 @@ const BaseLayout = ({
|
||||
{/* 顶部导航栏 */}
|
||||
<TopNav tags={tags} post={post} posts={totalPosts} currentSearch={currentSearch} categories={categories} currentCategory={currentCategory} />
|
||||
|
||||
{/* {useRouter().asPath === '/' && <Header/>} */}
|
||||
{/* 首页头图 */}
|
||||
{router.asPath === '/' && <Header/>}
|
||||
|
||||
<div id='wrapper' className='flex justify-center flex-1 mx-auto md:pt-12 pb-12'>
|
||||
<div id='wrapper' className='flex justify-center flex-1 mx-auto md:pt-16 pb-12'>
|
||||
|
||||
{/* <div id='left' className='hidden lg:block flex-col w-72'>
|
||||
<SideAreaLeft targetRef={targetRef} title={meta.title} post={post} posts={totalPosts} tags={tags} currentSearch={currentSearch} currentTag={currentTag} categories={categories} currentCategory={currentCategory} />
|
||||
@@ -89,7 +93,7 @@ const BaseLayout = ({
|
||||
</div>
|
||||
|
||||
<div id='right' className='hidden lg:block flex-col w-72 mr-5'>
|
||||
<SideAreaRight post={post} posts={totalPosts} tags={tags} currentSearch={currentSearch} currentTag={currentTag} categories={categories} currentCategory={currentCategory}/>
|
||||
<SideAreaRight targetRef={targetRef} post={post} posts={totalPosts} tags={tags} currentSearch={currentSearch} currentTag={currentTag} categories={categories} currentCategory={currentCategory}/>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
BIN
public/bg_image.jpg
Normal file
BIN
public/bg_image.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 538 KiB |
@@ -151,12 +151,12 @@ nav {
|
||||
|
||||
.glassmorphism{
|
||||
background: rgba(255, 255, 255, 0.2);
|
||||
-webkit-backdrop-filter: blur(5px);
|
||||
backdrop-filter: blur(5px);
|
||||
-webkit-backdrop-filter: blur(3px);
|
||||
backdrop-filter: blur(3px);
|
||||
}
|
||||
|
||||
.dark .glassmorphism{
|
||||
background: rgba(31, 41, 55, .5);
|
||||
-webkit-backdrop-filter: blur(5px);
|
||||
backdrop-filter: blur(5px);
|
||||
background: rgba(31, 41, 55, 0.2);
|
||||
-webkit-backdrop-filter: blur(3px);
|
||||
backdrop-filter: blur(3px);
|
||||
}
|
||||
Reference in New Issue
Block a user