Skip to content

Commit 70309ed

Browse files
authored
Merge pull request #2357 from didi/fix-web-pull-down
fix: 输出 web 页面 onReachBottom 触发异常 & 页面元素 position fixed 渲染异常问题
2 parents 6f22beb + c9cf46b commit 70309ed

File tree

1 file changed

+17
-5
lines changed
  • packages/core/src/helper/MpxScroll

1 file changed

+17
-5
lines changed

packages/core/src/helper/MpxScroll/index.js

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ export default class MpxScroll {
5757
const isIntersecting = change.isIntersecting
5858
this.isIntersecting = isIntersecting
5959
if (!isIntersecting) {
60-
// 非 inter section 状态下及时清除 transtorm,以免影响正常滚动时元素的 fixed 定位
61-
this.el.style.cssText = ''
60+
// 非 inter section 状态下及时清除 transform,以免影响正常滚动时元素的 fixed 定位
61+
this.el.style.transform = ''
6262
this.pullDownEventRegister && this.pullDownEventRegister.destroy()
6363
} else {
6464
this.pullDownEventRegister = new EventRegister(this.el, [
@@ -103,7 +103,12 @@ export default class MpxScroll {
103103

104104
transformPage (distance) {
105105
this.translateY = distance
106-
this.el.style.cssText = `transform: translateY(${distance}px)`
106+
if (distance === 0) {
107+
// 距离为 0 时移除 transform,避免影响页面 fixed 定位
108+
this.el.style.transform = ''
109+
} else {
110+
this.el.style.transform = `translateY(${distance}px)`
111+
}
107112
}
108113

109114
onTouchEnd (e) {
@@ -219,8 +224,15 @@ export default class MpxScroll {
219224
}
220225

221226
onReachBottom (onReachBottomDistance, callback) {
222-
const { bottom } = this.el.getBoundingClientRect()
223-
const mark = bottom - window.innerHeight <= onReachBottomDistance
227+
const scrollTop = getScrollTop()
228+
const scrollHeight = document.documentElement.scrollHeight
229+
const clientHeight = window.innerHeight
230+
231+
// 使用 scrollHeight 判断实际内容高度是否超过视口,只有可滚动时才计算触底
232+
const scrollable = scrollHeight > clientHeight
233+
// 距离底部的距离 = 内容总高度 - (当前滚动位置 + 视口高度)
234+
const distanceToBottom = scrollHeight - (scrollTop + clientHeight)
235+
const mark = scrollable && (distanceToBottom <= onReachBottomDistance)
224236

225237
if (!this.bottomReached && mark) {
226238
this.bottomReached = true

0 commit comments

Comments
 (0)