From 3b79eff2649a05a3757fb8b154590a1497dcb749 Mon Sep 17 00:00:00 2001 From: syn-zeta Date: Thu, 18 May 2017 13:28:53 -0700 Subject: [PATCH] Fixes #43: Patch distance calculation bug Fixes bug that was introduced in https://github.com/PeachScript/vue-infinite-loading/pull/48, and released in (now deprecated) 2.1.1. --- src/components/InfiniteLoading.vue | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/components/InfiniteLoading.vue b/src/components/InfiniteLoading.vue index d0051d0..022616e 100644 --- a/src/components/InfiniteLoading.vue +++ b/src/components/InfiniteLoading.vue @@ -46,22 +46,22 @@ */ function getCurrentDistance(elm, dir) { let distance; - const scrollTop = isNaN(elm.scrollTop) ? elm.pageYOffset : elm.scrollTop; + if (dir === 'top') { - distance = scrollTop; + distance = isNaN(elm.scrollTop) ? elm.pageYOffset : elm.scrollTop; } else { let scrollElmHeight; - let elOffsetTopFromScrollElm = this.$el.getBoundingClientRect().top; + let elOffsetTop = this.$el.getBoundingClientRect().top; if (elm === window) { scrollElmHeight = window.innerHeight; } else { - scrollElmHeight = elm.getBoundingClientRect().height; - elOffsetTopFromScrollElm -= elm.getBoundingClientRect().top; + scrollElmHeight = elm.clientHeight; + elOffsetTop -= elm.getBoundingClientRect().top; } - - distance = elOffsetTopFromScrollElm - scrollElmHeight - (elm.offsetTop || 0); + distance = elOffsetTop - scrollElmHeight; } + return distance; }