Skip to content

Commit b38de89

Browse files
author
fangzhizheng1
committed
feat: 无限滚动增加默认滚定位置
1 parent 994800f commit b38de89

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

src/packages/infiniteloading/infiniteloading.tsx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ export interface InfiniteLoadingProps extends BasicComponent {
2323
onRefresh: () => Promise<void>
2424
onLoadMore: () => Promise<void>
2525
onScroll: (param: number) => void
26+
defaultScrollTop?: number
2627
}
2728

2829
declare let window: Window & { webkitRequestAnimationFrame: any } & {
@@ -60,6 +61,7 @@ export const InfiniteLoading: FunctionComponent<
6061
onRefresh,
6162
onLoadMore,
6263
onScroll,
64+
defaultScrollTop,
6365
...restProps
6466
} = {
6567
...defaultProps,
@@ -77,6 +79,16 @@ export const InfiniteLoading: FunctionComponent<
7779

7880
const classes = classNames(classPrefix, className, `${classPrefix}-${type}`)
7981

82+
useEffect(() => {
83+
if (defaultScrollTop) {
84+
const childHeight = (getRefreshTop().firstElementChild as HTMLElement).offsetHeight || 0;
85+
refreshMaxH.current = Math.floor(childHeight * 1 + 10);
86+
setTimeout(() =>{
87+
scrollEl.current.scrollTop = defaultScrollTop
88+
}, 10)
89+
}
90+
}, [defaultScrollTop]);
91+
8092
useEffect(() => {
8193
if (target && document.getElementById(target)) {
8294
scrollEl.current = document.getElementById(target)

0 commit comments

Comments
 (0)