Skip to content

Commit ebb91d2

Browse files
committed
Fix distance calculate error while the scroll parent is window
1 parent f4623af commit ebb91d2

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

src/components/InfiniteLoading.vue

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,17 @@
5050
if (dir === 'top') {
5151
distance = scrollTop;
5252
} else {
53-
const elmBoundingClientRect = elm.getBoundingClientRect();
54-
const scrollElmHeight = elm === window ?
55-
window.innerHeight :
56-
elmBoundingClientRect.height;
57-
const elOffsetTopFromScrollElm = this.$el.getBoundingClientRect().top -
58-
elmBoundingClientRect.top;
53+
let scrollElmHeight;
54+
let elOffsetTopFromScrollElm;
55+
56+
if (elm === window) {
57+
scrollElmHeight = window.innerHeight;
58+
elOffsetTopFromScrollElm = this.$el.getBoundingClientRect().top;
59+
} else {
60+
scrollElmHeight = elm.getBoundingClientRect().height;
61+
elOffsetTopFromScrollElm = this.$el.getBoundingClientRect().top -
62+
elm.getBoundingClientRect().top;
63+
}
5964
6065
distance = elOffsetTopFromScrollElm - scrollTop - scrollElmHeight - (elm.offsetTop || 0);
6166
}

0 commit comments

Comments
 (0)