Skip to content

Commit 4a96bd4

Browse files
committed
Improve the way to calculate distance to fix #36
1 parent c47dd95 commit 4a96bd4

File tree

1 file changed

+6
-11
lines changed

1 file changed

+6
-11
lines changed

src/components/InfiniteLoading.vue

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -48,16 +48,11 @@
4848
if (dir === 'top') {
4949
distance = scrollTop;
5050
} else {
51-
const styles = getComputedStyle(elm === window ? document.body : elm);
52-
const innerHeight = elm === window
53-
? window.innerHeight
54-
: parseInt(styles.height, 10);
55-
const scrollHeight = elm === window
56-
? document.body.scrollHeight
57-
: elm.scrollHeight;
58-
const paddingTop = parseInt(styles.paddingTop, 10);
59-
const paddingBottom = parseInt(styles.paddingBottom, 10);
60-
distance = scrollHeight - innerHeight - scrollTop - paddingTop - paddingBottom;
51+
const scrollElmHeight = elm === window ?
52+
window.innerHeight :
53+
elm.getBoundingClientRect().height;
54+
55+
distance = this.$el.offsetTop - scrollTop - scrollElmHeight - (elm.offsetTop || 0);
6156
}
6257
return distance;
6358
}
@@ -122,7 +117,7 @@
122117
},
123118
methods: {
124119
attemptLoad() {
125-
const currentDistance = getCurrentDistance(this.scrollParent, this.direction);
120+
const currentDistance = getCurrentDistance.bind(this)(this.scrollParent, this.direction);
126121
if (!this.isComplete && currentDistance <= this.distance) {
127122
this.isLoading = true;
128123
this.onInfinite.call();

0 commit comments

Comments
 (0)