Skip to content

Commit a91c111

Browse files
committed
add compensation accuracy for height change, close ant-design/ant-design-landing#167
1 parent 61d4b63 commit a91c111

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "rc-scroll-anim",
3-
"version": "2.7.2",
3+
"version": "2.7.3",
44
"description": "scroll-anim anim component for react",
55
"keywords": [
66
"react",

src/ScrollScreen.jsx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,11 @@ class ScrollScreenClass {
5454
const domOffsetTop = dom.offsetTop;
5555
const domHeight = dom.getBoundingClientRect().height;
5656
if (this.scrollTop >= domOffsetTop && this.scrollTop < domOffsetTop + domHeight) {
57-
this.num = i;
58-
this.toHeight = domOffsetTop;
57+
let exceed = (this.scrollTop - dom.offsetTop) / domHeight;
58+
// 当前屏超过80%到下半屏, scrollOverPack 会动态改高度;
59+
exceed = exceed > 0.8 ? 1 : 0;
60+
this.num = i + exceed;
61+
this.toHeight = domOffsetTop + exceed * domHeight;
5962
}
6063
});
6164
let tooNum;
@@ -125,7 +128,8 @@ class ScrollScreenClass {
125128
const overflowY = style.overflowY;
126129
const isScrollOverflow = overflow === 'auto' || overflow === 'scroll' || overflow === 'overlay'
127130
|| overflowY === 'auto' || overflowY === 'scroll' || overflowY === 'overlay';
128-
if (dom === document.body || !dom) {
131+
// dom.parentNode === document 解决在滚动条上滚动取不到 body;
132+
if (dom === document.body || !dom || dom.parentNode === document) {
129133
return false;
130134
} else if (dom.scrollHeight > dom.offsetHeight
131135
&& isScrollOverflow

0 commit comments

Comments
 (0)