This commit is contained in:
tangly1024
2021-10-14 19:37:28 +08:00
parent a07894bd46
commit 85bf342718
2 changed files with 4 additions and 2 deletions

View File

@@ -16,8 +16,9 @@ const JumpToTop = ({ targetRef, showPercent = true }) => {
const [percent, changePercent] = useState(0)
const scrollListener = useCallback(throttle(() => {
// 处理是否显示回到顶部按钮
const clientHeight = targetRef ? (targetRef.current.clientHeight) : 0
const scrollY = window.pageYOffset
const fullHeight = targetRef.current.clientHeight - window.outerHeight
const fullHeight = clientHeight - window.outerHeight
const shouldShow = scrollY > 100
if (shouldShow !== show) {
switchShow(shouldShow)

View File

@@ -10,8 +10,9 @@ const Progress = ({ targetRef }) => {
const [percent, changePercent] = useState(0)
const scrollListener = useCallback(throttle(() => {
if (targetRef.current) {
const clientHeight = targetRef ? (targetRef.current.clientHeight) : 0
const scrollY = window.pageYOffset
const fullHeight = targetRef.current.clientHeight - window.outerHeight
const fullHeight = clientHeight - window.outerHeight
let per = parseFloat(((scrollY / fullHeight * 100)).toFixed(0))
if (per > 100) per = 100
changePercent(per)