Skip to content

Commit 466d74e

Browse files
authored
Merge pull request #37 from oumoussa98/patch-1
Patch 1
2 parents 1a5751d + 14a9b9c commit 466d74e

File tree

4 files changed

+10
-21
lines changed

4 files changed

+10
-21
lines changed

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "v3-infinite-loading",
3-
"version": "1.2.0",
3+
"version": "1.2.1",
44
"description": "Infinite scroller component for vuejs-3",
55
"homepage": "https://vue3-infinite-loading.netlify.app/",
66
"repository": {

src/components/InfiniteLoading.vue

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import {
88
stateHandler,
99
initEmitter,
1010
isVisible,
11-
getScrollHeight,
1211
} from "../utils.js";
1312
1413
const emit = defineEmits(["infinite"]);
@@ -38,12 +37,13 @@ const params = {
3837
3938
const stateWatcher = () =>
4039
watch(state, async newVal => {
41-
const parentEl = params.parentEl;
42-
const prevHeight = getScrollHeight(parentEl);
40+
const parentEl = params.parentEl || document.documentElement;
41+
const prevHeight = parentEl.scrollHeight;
4342
await nextTick();
44-
const currHeight = getScrollHeight(parentEl);
45-
if (newVal == "loaded" && top) parentEl.scrollTop = currHeight - prevHeight;
46-
if (newVal == "loaded" && isVisible(infiniteLoading.value, parentEl)) params.emit();
43+
if (newVal == "loaded" && top)
44+
parentEl.scrollTop = parentEl.scrollHeight - prevHeight;
45+
if (newVal == "loaded" && isVisible(infiniteLoading.value, params.parentEl))
46+
params.emit();
4747
if (newVal == "complete") stopObserver();
4848
});
4949

src/utils.js

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,6 @@ const isVisible = (el, view) => {
2727
return elRect.top >= viewRect.top && elRect.bottom <= viewRect.bottom;
2828
};
2929

30-
const getScrollHeight = el => {
31-
return el?.scrollHeight || document.documentElement.scrollHeight;
32-
};
33-
3430
let observer;
3531
const startObserver = params => {
3632
params.parentEl = document.querySelector(params.target) || null;
@@ -53,11 +49,4 @@ const stopObserver = () => {
5349
observer.disconnect();
5450
};
5551

56-
export {
57-
startObserver,
58-
stopObserver,
59-
stateHandler,
60-
initEmitter,
61-
isVisible,
62-
getScrollHeight,
63-
};
52+
export { startObserver, stopObserver, stateHandler, initEmitter, isVisible };

0 commit comments

Comments
 (0)