fix: recalculate scrolltop when scroll.y changes
This commit is contained in:
parent
6b8ad2414e
commit
06a8d7f6ff
19
src/Table.js
19
src/Table.js
|
@ -276,11 +276,22 @@ class Table extends Component {
|
|||
if (prevScrollY && currentScrollY && (prevScrollY !== currentScrollY) && this.props.lazyLoad && !this.props.ignoreScrollYChange) {
|
||||
this.bodyTable.scrollTop = 0
|
||||
} else if (this.props.ignoreScrollYChange && currentScrollY && prevScrollY && (prevScrollY !== currentScrollY)) {
|
||||
const distance = this.bodyTable.scrollTop + (currentScrollY - prevScrollY)
|
||||
if (distance < 0) {
|
||||
this.bodyTable.scrollTop = 0
|
||||
const bodyScrollTop = this.bodyTable.scrollTop
|
||||
if (bodyScrollTop === 0) { // 在顶部的时候,滚动条不用动
|
||||
this.bodyTable.scrollTop = 0;
|
||||
} else {
|
||||
this.bodyTable.scrollTop = distance
|
||||
const distance = bodyScrollTop + currentScrollY - prevScrollY;
|
||||
if (distance < 0) {
|
||||
this.bodyTable.scrollTop = 0;
|
||||
} else {
|
||||
const { scrollHeight, scrollTop } = this.bodyTable
|
||||
const bottomDistance = Math.abs(scrollHeight - scrollTop - prevScrollY) // 在最底部的时候也不用滚动滚动条
|
||||
if (bottomDistance < 5) { // 有些dom计算不是十分精确,设置一个值来缓冲一下
|
||||
this.bodyTable.scrollTop = scrollTop + prevScrollY - currentScrollY
|
||||
} else {
|
||||
this.bodyTable.scrollTop = distance;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// 是否传入 scroll中的y属性,如果传入判断是否是整数,如果是则进行比较 。bodyTable 的clientHeight进行判断
|
||||
|
|
Loading…
Reference in New Issue