提交 d9f85763 编写于 作者: Q qiang

fix: 解决QQ浏览器“上拉加载更多”无法触发的问题

上级 8723ceaf
...@@ -58,6 +58,7 @@ export function pageScrollTo ({ ...@@ -58,6 +58,7 @@ export function pageScrollTo ({
// bodyStyle.webkitTransform = `translateY(${documentElement.scrollTop}px) translateZ(0)` // bodyStyle.webkitTransform = `translateY(${documentElement.scrollTop}px) translateZ(0)`
} }
let testReachBottomTimer
export function createScrollListener (pageId, { export function createScrollListener (pageId, {
enablePageScroll, enablePageScroll,
enablePageReachBottom, enablePageReachBottom,
...@@ -72,13 +73,12 @@ export function createScrollListener (pageId, { ...@@ -72,13 +73,12 @@ export function createScrollListener (pageId, {
function isReachBottom () { function isReachBottom () {
const { const {
clientHeight,
scrollHeight scrollHeight
} = document.documentElement } = document.documentElement
// 部分浏览器窗口高度变化后document.documentelement.clientheight不会变化,采用window.innerHeight
const windowHeight = window.innerHeight
const scrollY = window.scrollY const scrollY = window.scrollY
let isBottom = scrollY > 0 && scrollHeight > windowHeight && (scrollY + windowHeight + onReachBottomDistance) >= scrollHeight
let isBottom = scrollY > 0 && scrollHeight > clientHeight && (scrollY + clientHeight + onReachBottomDistance) >=
scrollHeight
if (isBottom && !hasReachBottom) { if (isBottom && !hasReachBottom) {
hasReachBottom = true hasReachBottom = true
return true return true
...@@ -108,18 +108,28 @@ export function createScrollListener (pageId, { ...@@ -108,18 +108,28 @@ export function createScrollListener (pageId, {
scrollTop scrollTop
}) })
} }
function testReachBottom () {
if (enablePageReachBottom && onReachBottom && isReachBottom()) { if (isReachBottom()) {
publishHandler('onReachBottom', {}, pageId) publishHandler('onReachBottom', {}, pageId)
onReachBottom = false onReachBottom = false
setTimeout(function () { setTimeout(function () {
onReachBottom = true onReachBottom = true
}, 350) }, 350)
return true
}
}
if (enablePageReachBottom && onReachBottom) {
if (testReachBottom()) {
} else {
// 解决部分浏览器滚动中js获取窗口高度不准确导致的问题
testReachBottomTimer = setTimeout(testReachBottom, 300)
}
} }
ticking = false ticking = false
} }
return function onScroll () { return function onScroll () {
clearTimeout(testReachBottomTimer)
if (!ticking) { if (!ticking) {
requestAnimationFrame(trigger) requestAnimationFrame(trigger)
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册