Remove unused infinite scroll component

The infinite scroll component is not mean to be used in svelte project.
It's for HTMX project.
This commit is contained in:
ditatompel 2024-05-08 00:41:22 +07:00
parent bc90c8bf3c
commit e53a54b276
No known key found for this signature in database
GPG key ID: 31D3D06D77950979

View file

@ -1,50 +0,0 @@
<script>
import { onDestroy, createEventDispatcher } from 'svelte';
export let threshold = 0;
export let horizontal = false;
export let hasMore = true;
/** @type {any} */
let elementScroll;
const dispatch = createEventDispatcher();
let isLoadMore = false;
/** @type {any} */
let component;
$: {
if (component || elementScroll) {
const element = elementScroll ? elementScroll : component.parentNode;
element.addEventListener('scroll', onScroll);
element.addEventListener('resize', onScroll);
}
}
/** @param {any} e */
const onScroll = (e) => {
const offset = horizontal
? e.target.scrollWidth - e.target.clientWidth - e.target.scrollLeft
: e.target.scrollHeight - e.target.clientHeight - e.target.scrollTop;
if (offset <= threshold) {
if (!isLoadMore && hasMore) {
dispatch('loadMore');
}
isLoadMore = true;
} else {
isLoadMore = false;
}
};
onDestroy(() => {
if (component || elementScroll) {
const element = elementScroll ? elementScroll : component.parentNode;
element.removeEventListener('scroll', null);
element.removeEventListener('resize', null);
}
});
</script>
<div bind:this={component} class="w-0" />