2024-08-04 14:36:44 +00:00
|
|
|
<script lang="ts">
|
|
|
|
import { createEventDispatcher, onMount } from 'svelte';
|
|
|
|
const dispatch = createEventDispatcher();
|
|
|
|
|
|
|
|
let loaderElement: HTMLElement;
|
|
|
|
|
|
|
|
onMount(() => {
|
|
|
|
const observer = new IntersectionObserver(
|
|
|
|
(entries, observer) => {
|
|
|
|
entries.forEach((entry) => {
|
|
|
|
if (entry.isIntersecting) {
|
|
|
|
dispatch('visible');
|
|
|
|
// observer.unobserve(loaderElement); // Stop observing until content is loaded
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
{
|
|
|
|
root: null, // viewport
|
|
|
|
rootMargin: '0px',
|
2024-08-04 16:20:59 +00:00
|
|
|
threshold: 0.1 // When 10% of the loader is visible
|
2024-08-04 14:36:44 +00:00
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
observer.observe(loaderElement);
|
|
|
|
});
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<div bind:this={loaderElement}>
|
|
|
|
<slot />
|
|
|
|
</div>
|