|
39 | 39 | } |
40 | 40 |
|
41 | 41 | /** |
42 | | - * get current distance from footer |
43 | | - * @param {DOM} elm scroll element |
44 | | - * @param {String} dir calculate direction |
| 42 | + * get current distance from bottom |
| 43 | + * @param {DOM} scrollElm scroll element |
| 44 | + * @param {DOM} infiniteElm infinite element |
| 45 | + * @param {String} dir calculate direction |
45 | 46 | * @return {Number} distance |
46 | 47 | */ |
47 | | - function getCurrentDistance(elm, dir) { |
| 48 | + function getCurrentDistance(scrollElm, infiniteElm, dir) { |
48 | 49 | let distance; |
49 | 50 |
|
50 | 51 | if (dir === 'top') { |
51 | | - distance = isNaN(elm.scrollTop) ? elm.pageYOffset : elm.scrollTop; |
| 52 | + distance = isNaN(scrollElm.scrollTop) ? scrollElm.pageYOffset : scrollElm.scrollTop; |
52 | 53 | } else { |
53 | | - let scrollElmHeight; |
54 | | - let elOffsetTop = this.$el.getBoundingClientRect().top; |
| 54 | + const infiniteElmOffsetTopFromBottom = infiniteElm.getBoundingClientRect().top; |
| 55 | + const scrollElmOffsetTopFromBottom = scrollElm === window ? |
| 56 | + window.innerHeight : |
| 57 | + scrollElm.getBoundingClientRect().bottom; |
55 | 58 |
|
56 | | - if (elm === window) { |
57 | | - scrollElmHeight = window.innerHeight; |
58 | | - } else { |
59 | | - scrollElmHeight = elm.clientHeight; |
60 | | - elOffsetTop -= elm.getBoundingClientRect().top; |
61 | | - } |
62 | | - distance = elOffsetTop - scrollElmHeight; |
| 59 | + distance = infiniteElmOffsetTopFromBottom - scrollElmOffsetTopFromBottom; |
63 | 60 | } |
64 | 61 |
|
65 | 62 | return distance; |
|
131 | 128 | }, |
132 | 129 | methods: { |
133 | 130 | attemptLoad() { |
134 | | - const currentDistance = getCurrentDistance.bind(this)(this.scrollParent, this.direction); |
| 131 | + const currentDistance = getCurrentDistance(this.scrollParent, this.$el, this.direction); |
135 | 132 | if (!this.isComplete && currentDistance <= this.distance) { |
136 | 133 | this.isLoading = true; |
137 | 134 | this.onInfinite.call(); |
|
0 commit comments