Skip to content

Commit c466d76

Browse files
committed
Improve the way to calculate distance to fix #36
1 parent 78b8ee6 commit c466d76

File tree

1 file changed

+5
-11
lines changed

1 file changed

+5
-11
lines changed

src/components/InfiniteLoading.vue

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -49,17 +49,11 @@
4949
if (dir === 'top') {
5050
distance = scrollTop;
5151
} else {
52-
const styles = getComputedStyle(elm === window ? document.body : elm);
53-
const innerHeight = elm === window
54-
? window.innerHeight
55-
: parseInt(styles.height, 10);
56-
const scrollHeight = elm === window
57-
? document.body.scrollHeight
58-
: elm.scrollHeight;
59-
const paddingTop = parseInt(styles.paddingTop, 10);
60-
const paddingBottom = parseInt(styles.paddingBottom, 10);
52+
const scrollElmHeight = elm === window ?
53+
window.innerHeight :
54+
elm.getBoundingClientRect().height;
6155
62-
distance = scrollHeight - innerHeight - scrollTop - paddingTop - paddingBottom;
56+
distance = this.$el.offsetTop - scrollTop - scrollElmHeight - (elm.offsetTop || 0);
6357
}
6458
6559
return distance;
@@ -129,7 +123,7 @@
129123
},
130124
methods: {
131125
attemptLoad() {
132-
const currentDistance = getCurrentDistance(this.scrollParent, this.direction);
126+
const currentDistance = getCurrentDistance.bind(this)(this.scrollParent, this.direction);
133127
if (!this.isComplete && currentDistance <= this.distance) {
134128
this.isLoading = true;
135129
this.onInfinite.call();

0 commit comments

Comments
 (0)