diff --git a/themes/matery/LayoutBase.js b/themes/matery/LayoutBase.js index 6280b165..f9e3e30b 100644 --- a/themes/matery/LayoutBase.js +++ b/themes/matery/LayoutBase.js @@ -32,7 +32,7 @@ const LayoutBase = props => { const fullHeight = clientHeight - window.outerHeight let per = parseFloat(((scrollY / fullHeight) * 100).toFixed(0)) if (per > 100) per = 100 - const shouldShow = scrollY > 100 && per > 0 + const shouldShow = scrollY > 300 && per > 0 if (shouldShow !== show) { switchShow(shouldShow) @@ -72,6 +72,7 @@ const LayoutBase = props => {
+ {/* 右下角悬浮 */}
{ const { post, lock, validPassword } = props - const drawerRight = useRef(null) + const drawerRight = React.useRef(null) + + const [show, switchShow] = React.useState(false) + + const scrollListener = () => { + const scrollY = window.pageYOffset + const shouldShow = scrollY > 220 + + if (shouldShow !== show) { + switchShow(shouldShow) + } + } + React.useEffect(() => { + document.addEventListener('scroll', scrollListener) + return () => document.removeEventListener('scroll', scrollListener) + }, [show]) if (!post) { return { showTag={false} floatSlot={floatSlot} > +
{lock && } @@ -88,10 +105,13 @@ export const LayoutSlug = props => {
}
- {post.type === 'Post' && } -
+ + {show &&
+ +
} +
diff --git a/themes/matery/components/Catalog.js b/themes/matery/components/Catalog.js index c51ee499..0f4e6db6 100644 --- a/themes/matery/components/Catalog.js +++ b/themes/matery/components/Catalog.js @@ -10,10 +10,6 @@ import Progress from './Progress' * @constructor */ const Catalog = ({ toc }) => { - // 无目录就直接返回空 - if (!toc || toc.length < 1) { - return <> - } // 监听滚动事件 React.useEffect(() => { window.addEventListener('scroll', actionSectionScrollSpy) @@ -57,12 +53,17 @@ const Catalog = ({ toc }) => { tRef?.current?.scrollTo({ top: 28 * index, behavior: 'smooth' }) }, throttleMs)) - return
-
目录
+ // 无目录就直接返回空 + if (!toc || toc.length < 1) { + return <> + } + + return
+
目录
-
+