@@ -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