-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: added loading of additional grid pages
- Loading branch information
1 parent
a292816
commit 279e36a
Showing
4 changed files
with
108 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<script lang="ts"> | ||
import { onDestroy, createEventDispatcher } from "svelte"; | ||
export let threshold = 0; | ||
export let horizontal = false; | ||
export let hasMore = true; | ||
const dispatch = createEventDispatcher(); | ||
let isLoadMore = false; | ||
let component: any; | ||
$: { | ||
if (component) { | ||
const element = component.parentNode.parentNode; | ||
element.addEventListener("scroll", onScroll); | ||
element.addEventListener("resize", onScroll); | ||
} | ||
} | ||
function onScroll(e: any) { | ||
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) { | ||
const element = component.parentNode.parentNode; | ||
element.removeEventListener("scroll", null); | ||
element.removeEventListener("resize", null); | ||
} | ||
}); | ||
</script> | ||
|
||
<div bind:this={component} style="width:0px" /> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters