Skip to content

Commit

Permalink
refactor: 重构代码
Browse files Browse the repository at this point in the history
  • Loading branch information
crazylxr committed Sep 26, 2024
1 parent 82e55ff commit 9124e5b
Showing 1 changed file with 8 additions and 12 deletions.
20 changes: 8 additions & 12 deletions packages/hooks/src/useInfiniteScroll/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -106,20 +106,14 @@ const useInfiniteScroll = <TData extends Data>(
};

const scrollMethod = () => {
let el = getTargetElement(target);
if (!el) {
return;
}

el = el === document ? document.documentElement : el;
const el = getTargetElement(target);
if (!el) return;

const scrollTop = getScrollTop(el);
const scrollHeight = getScrollHeight(el);
const clientHeight = getClientHeight(el);
const targetEl = el === document ? document.documentElement : el;
const scrollTop = getScrollTop(targetEl);
const scrollHeight = getScrollHeight(targetEl);
const clientHeight = getClientHeight(targetEl);

if (!isScrollToTop && scrollHeight - scrollTop <= clientHeight + threshold) {
loadMore();
}
if (isScrollToTop) {
if (
lastScrollTop.current !== undefined &&
Expand All @@ -130,6 +124,8 @@ const useInfiniteScroll = <TData extends Data>(
}
lastScrollTop.current = scrollTop;
scrollBottom.current = scrollHeight - scrollTop;
} else if (scrollHeight - scrollTop <= clientHeight + threshold) {
loadMore();
}
};

Expand Down

0 comments on commit 9124e5b

Please sign in to comment.