mirror of
https://github.com/d0zingcat/NotionNext.git
synced 2026-06-07 23:16:52 +00:00
hexo 微调,添加随机跳转按钮
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import throttle from 'lodash.throttle'
|
||||
import { useCallback, useEffect, useState } from 'react'
|
||||
import FloatDarkModeButton from './FloatDarkModeButton'
|
||||
import JumpToTopButton from './JumpToTopButton'
|
||||
import ButtonDarkModeFloat from './ButtonFloatDarkMode'
|
||||
import ButtonJumpToTop from './ButtonJumpToTop'
|
||||
|
||||
/**
|
||||
* 悬浮在右下角的按钮,当页面向下滚动100px时会出现
|
||||
@@ -10,20 +10,22 @@ import JumpToTopButton from './JumpToTopButton'
|
||||
*/
|
||||
export default function RightFloatArea({ floatSlot }) {
|
||||
const [showFloatButton, switchShow] = useState(false)
|
||||
const scrollListener = useCallback(throttle(() => {
|
||||
const targetRef = document.getElementById('wrapper')
|
||||
const clientHeight = targetRef?.clientHeight
|
||||
const scrollY = window.pageYOffset
|
||||
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 scrollListener = useCallback(
|
||||
throttle(() => {
|
||||
const targetRef = document.getElementById('wrapper')
|
||||
const clientHeight = targetRef?.clientHeight
|
||||
const scrollY = window.pageYOffset
|
||||
const fullHeight = clientHeight - window.outerHeight
|
||||
let per = parseFloat(((scrollY / fullHeight) * 100).toFixed(0))
|
||||
if (per > 100) per = 100
|
||||
const shouldShow = scrollY > 100 && per > 0
|
||||
|
||||
// 右下角显示悬浮按钮
|
||||
if (shouldShow !== showFloatButton) {
|
||||
switchShow(shouldShow)
|
||||
}
|
||||
}, 200))
|
||||
// 右下角显示悬浮按钮
|
||||
if (shouldShow !== showFloatButton) {
|
||||
switchShow(shouldShow)
|
||||
}
|
||||
}, 200)
|
||||
)
|
||||
|
||||
useEffect(() => {
|
||||
document.addEventListener('scroll', scrollListener)
|
||||
@@ -31,12 +33,17 @@ export default function RightFloatArea({ floatSlot }) {
|
||||
}, [])
|
||||
|
||||
return (
|
||||
<div className={(showFloatButton ? 'opacity-100 ' : 'invisible opacity-0') + ' duration-300 transition-all bottom-12 right-1 fixed justify-end z-20 text-white bg-indigo-500 dark:bg-hexo-black-gray rounded-sm'}>
|
||||
<div className={'justify-center flex flex-col items-center cursor-pointer'}>
|
||||
<FloatDarkModeButton />
|
||||
{floatSlot}
|
||||
<JumpToTopButton />
|
||||
</div>
|
||||
</div>
|
||||
<div
|
||||
className={
|
||||
(showFloatButton ? 'opacity-100 ' : 'invisible opacity-0') +
|
||||
' duration-300 transition-all bottom-12 right-1 fixed justify-end z-20 text-white bg-indigo-500 dark:bg-hexo-black-gray rounded-sm'
|
||||
}>
|
||||
<div
|
||||
className={'justify-center flex flex-col items-center cursor-pointer'}>
|
||||
<ButtonDarkModeFloat />
|
||||
{floatSlot}
|
||||
<ButtonJumpToTop />
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user