From e541260ef3ff3b98eec8bd7f1c609470cae552b6 Mon Sep 17 00:00:00 2001 From: neverland Date: Sat, 18 Jul 2020 18:53:40 +0800 Subject: [PATCH] fix(Calendar): rendering fails in some cases (#6812) --- src/calendar/index.js | 7 +++---- src/utils/dom/scroll.ts | 5 ++++- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/calendar/index.js b/src/calendar/index.js index 591e64a2c..7b70a65c1 100644 --- a/src/calendar/index.js +++ b/src/calendar/index.js @@ -244,14 +244,13 @@ export default createComponent({ onScroll() { const { body, months } = this.$refs; const top = getScrollTop(body); - const bottom = top + this.bodyHeight; const heights = months.map((item) => item.getHeight()); const heightSum = heights.reduce((a, b) => a + b, 0); // iOS scroll bounce may exceed the range - /* istanbul ignore next */ - if (top < 0 || (bottom > heightSum && top > 0)) { - return; + let bottom = top + this.bodyHeight; + if (bottom > heightSum && top > 0) { + bottom = heightSum; } let height = 0; diff --git a/src/utils/dom/scroll.ts b/src/utils/dom/scroll.ts index aa3f7f571..6d7457f74 100644 --- a/src/utils/dom/scroll.ts +++ b/src/utils/dom/scroll.ts @@ -40,7 +40,10 @@ export function getScroller(el: HTMLElement, root: ScrollElement = window) { } export function getScrollTop(el: ScrollElement): number { - return 'scrollTop' in el ? el.scrollTop : el.pageYOffset; + const top = 'scrollTop' in el ? el.scrollTop : el.pageYOffset; + + // iOS scroll bounce cause minus scrollTop + return Math.max(top, 0); } export function setScrollTop(el: ScrollElement, value: number) {