目录zIndex调整,封装导航隐藏函数,加入隐私协议链接

This commit is contained in:
tangly1024
2021-10-26 16:16:46 +08:00
parent 54b27aa368
commit 6258465203
3 changed files with 37 additions and 13 deletions

View File

@@ -10,6 +10,7 @@ const Footer = ({ fullWidth = true }) => {
<span className='fa fa-copyright leading-6'> {` ${y}`} <span> <a href='https://www.tangly1024.com/article/about' className='underline font-bold text-gray-100'>tangly1024.com</a>. Powered by <a href='https://notion.so' className='underline font-bold text-gray-100'>Notion</a> & <a href='https://vercel.com' className='underline font-bold text-gray-100'>Vercel</a>.</span> </span>
<br />
<span className='fa fa-shield leading-6 mr-2'> <a href='https://beian.miit.gov.cn/' className='ml-1 font-bold'>闽ICP备20010331号</a></span>
<span > <a href='/article/privacy-policy' className='ml-1 font-bold underline'>隐私政策</a></span>
<span id='busuanzi_container_site_pv' className='hidden'>
<a id='busuanzi_container_site_pv' target='_blank' className='fa fa-eye' rel='noreferrer'

View File

@@ -13,21 +13,11 @@ const BaseLayout = ({ children, layout, fullWidth, tags, meta, post, ...customMe
let windowTop = 0
const scrollTrigger = useCallback(throttle(() => {
const scrollS = window.scrollY
const nav = document.querySelector('#sticky-nav')
const sidebar = document.querySelector('#sidebar')
const tagsBar = document.querySelector('#tags-bar')
const rightToc = document.querySelector('#right-toc')
if (scrollS >= windowTop && scrollS > 10) {
nav && nav.classList.replace('top-0', '-top-16')
tagsBar && tagsBar.classList.replace('top-16', 'top-0')
sidebar && sidebar.classList.replace('top-20', 'top-2')
rightToc && rightToc.classList.replace('top-16', 'top-0')
hiddenNav()
windowTop = scrollS
} else {
nav && nav.classList.replace('-top-16', 'top-0')
tagsBar && tagsBar.classList.replace('top-0', 'top-16')
sidebar && sidebar.classList.replace('top-2', 'top-20')
rightToc && rightToc.classList.replace('top-0', 'top-16')
showNav()
windowTop = scrollS
}
}, 200))
@@ -35,6 +25,7 @@ const BaseLayout = ({ children, layout, fullWidth, tags, meta, post, ...customMe
// 监听滚动
useEffect(() => {
window.addEventListener('scroll', scrollTrigger)
scrollTrigger()
return () => {
window.removeEventListener('scroll', scrollTrigger)
}
@@ -62,6 +53,38 @@ const BaseLayout = ({ children, layout, fullWidth, tags, meta, post, ...customMe
)
}
/**
* 隐藏导航
*/
const hiddenNav = () => {
if (document) {
const nav = document.querySelector('#sticky-nav')
const sidebar = document.querySelector('#sidebar')
const tagsBar = document.querySelector('#tags-bar')
const rightToc = document.querySelector('#right-toc')
nav && nav.classList.replace('top-0', '-top-16')
tagsBar && tagsBar.classList.replace('top-16', 'top-0')
sidebar && sidebar.classList.replace('top-20', 'top-2')
rightToc && rightToc.classList.replace('top-16', 'top-0')
}
}
/**
* 显示导航
*/
const showNav = () => {
if (document) {
const nav = document.querySelector('#sticky-nav')
const sidebar = document.querySelector('#sidebar')
const tagsBar = document.querySelector('#tags-bar')
const rightToc = document.querySelector('#right-toc')
nav && nav.classList.replace('-top-16', 'top-0')
tagsBar && tagsBar.classList.replace('top-0', 'top-16')
sidebar && sidebar.classList.replace('top-2', 'top-20')
rightToc && rightToc.classList.replace('top-0', 'top-16')
}
}
BaseLayout.propTypes = {
children: PropTypes.node
}

View File

@@ -141,7 +141,7 @@ const BlogPost = ({ post, blockMap, tags, prev, next }) => {
</div>
{/* 右侧目录 */}
<aside className='dark:bg-gray-800 bg-white'>
<aside className='dark:bg-gray-800 bg-white z-10'>
<section
className='h-full xl:static xl:block hidden top-0 right-0 fixed h-full w-52 dark:bg-gray-800 duration-500'>
<div id='right-toc' className='sticky top-16 duration-500'>