From d9f85763d7d598ffc3b8bb3b36f164553e5a8b87 Mon Sep 17 00:00:00 2001 From: qiang Date: Wed, 13 Nov 2019 11:50:10 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E8=A7=A3=E5=86=B3QQ=E6=B5=8F=E8=A7=88?= =?UTF-8?q?=E5=99=A8=E2=80=9C=E4=B8=8A=E6=8B=89=E5=8A=A0=E8=BD=BD=E6=9B=B4?= =?UTF-8?q?=E5=A4=9A=E2=80=9D=E6=97=A0=E6=B3=95=E8=A7=A6=E5=8F=91=E7=9A=84?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/core/view/bridge/subscribe/scroll.js | 32 ++++++++++++++++-------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/src/core/view/bridge/subscribe/scroll.js b/src/core/view/bridge/subscribe/scroll.js index a148d8a329..e28aacf1cf 100644 --- a/src/core/view/bridge/subscribe/scroll.js +++ b/src/core/view/bridge/subscribe/scroll.js @@ -58,6 +58,7 @@ export function pageScrollTo ({ // bodyStyle.webkitTransform = `translateY(${documentElement.scrollTop}px) translateZ(0)` } +let testReachBottomTimer export function createScrollListener (pageId, { enablePageScroll, enablePageReachBottom, @@ -72,13 +73,12 @@ export function createScrollListener (pageId, { function isReachBottom () { const { - clientHeight, scrollHeight } = document.documentElement + // 部分浏览器窗口高度变化后document.documentelement.clientheight不会变化,采用window.innerHeight + const windowHeight = window.innerHeight const scrollY = window.scrollY - - let isBottom = scrollY > 0 && scrollHeight > clientHeight && (scrollY + clientHeight + onReachBottomDistance) >= - scrollHeight + let isBottom = scrollY > 0 && scrollHeight > windowHeight && (scrollY + windowHeight + onReachBottomDistance) >= scrollHeight if (isBottom && !hasReachBottom) { hasReachBottom = true return true @@ -108,18 +108,28 @@ export function createScrollListener (pageId, { scrollTop }) } - - if (enablePageReachBottom && onReachBottom && isReachBottom()) { - publishHandler('onReachBottom', {}, pageId) - onReachBottom = false - setTimeout(function () { - onReachBottom = true - }, 350) + function testReachBottom () { + if (isReachBottom()) { + publishHandler('onReachBottom', {}, pageId) + onReachBottom = false + setTimeout(function () { + onReachBottom = true + }, 350) + return true + } + } + if (enablePageReachBottom && onReachBottom) { + if (testReachBottom()) { + } else { + // 解决部分浏览器滚动中js获取窗口高度不准确导致的问题 + testReachBottomTimer = setTimeout(testReachBottom, 300) + } } ticking = false } return function onScroll () { + clearTimeout(testReachBottomTimer) if (!ticking) { requestAnimationFrame(trigger) } -- GitLab