fix: 改变数据源时,scrollTop回到顶部

This commit is contained in:
gx2025f 2021-01-11 18:13:18 +08:00
parent 49be931c87
commit de7b4e58fb
5 changed files with 655 additions and 622 deletions

File diff suppressed because one or more lines are too long

2
dist/demo.css.map vendored

File diff suppressed because one or more lines are too long

1262
dist/demo.js vendored

File diff suppressed because one or more lines are too long

2
dist/demo.js.map vendored

File diff suppressed because one or more lines are too long

View File

@ -48,8 +48,9 @@ export default class InfiniteScroll extends Component {
let {treeList:newTreeList} = nextProps;
let {treeList:oldTreeList} = this.props;
if(newTreeList !== oldTreeList) {
const isNewDataLess = newTreeList.length < oldTreeList.length
this.treeList = newTreeList;
this.handleScrollY();
this.handleScrollY(isNewDataLess);
}
}
@ -193,7 +194,7 @@ export default class InfiniteScroll extends Component {
/**
* @description 根据返回的scrollTop计算当前的索引
*/
handleScrollY = () => {
handleScrollY = (isNewDataLess) => {
const { store } = this.props;
const parentElement = this.getParentElement(this.scrollComponent);
if (!parentElement) {
@ -222,7 +223,9 @@ export default class InfiniteScroll extends Component {
index += 1;
}
}
if (isNewDataLess) {
parentElement.scrollTop = 0
}
//true 为向下滚动, false 为向上滚动
let isScrollDown = index - currentIndex > 0 ? true : false;