aboutsummaryrefslogtreecommitdiff
path: root/src/lib/Lazy.svelte
diff options
context:
space:
mode:
authorFuwn <[email protected]>2026-03-01 16:20:51 -0800
committerFuwn <[email protected]>2026-03-01 16:21:02 -0800
commiteae5d24d9e79e59a19d4721caaeaa0ca650ecb33 (patch)
tree1b685bb248e051dfa26d2bfdebe6689402dd93c5 /src/lib/Lazy.svelte
parentchore(tooling): remove legacy eslint and prettier (diff)
downloaddue.moe-eae5d24d9e79e59a19d4721caaeaa0ca650ecb33.tar.xz
due.moe-eae5d24d9e79e59a19d4721caaeaa0ca650ecb33.zip
chore(biome): drop formatter style overrides
Diffstat (limited to 'src/lib/Lazy.svelte')
-rw-r--r--src/lib/Lazy.svelte39
1 files changed, 21 insertions, 18 deletions
diff --git a/src/lib/Lazy.svelte b/src/lib/Lazy.svelte
index 6386177b..489793cc 100644
--- a/src/lib/Lazy.svelte
+++ b/src/lib/Lazy.svelte
@@ -1,5 +1,5 @@
<script lang="ts">
-import { onMount, onDestroy } from 'svelte';
+import { onMount, onDestroy } from "svelte";
export let top = 0;
export let bottom = 0;
@@ -14,28 +14,31 @@ let percent = 0;
let visible = false;
let observer: IntersectionObserver;
-const intersectPercent = (entries: IntersectionObserverEntry[], observer: IntersectionObserver) => {
- for (let entry of entries)
- if (entry.target === element) {
- percent = Math.round(entry.intersectionRatio * 100);
- visible = entry.intersectionRatio >= threshold;
+const intersectPercent = (
+ entries: IntersectionObserverEntry[],
+ observer: IntersectionObserver,
+) => {
+ for (let entry of entries)
+ if (entry.target === element) {
+ percent = Math.round(entry.intersectionRatio * 100);
+ visible = entry.intersectionRatio >= threshold;
- if (visible && once) observer.unobserve(element);
+ if (visible && once) observer.unobserve(element);
- break;
- }
+ break;
+ }
};
onMount(() => {
- if ('IntersectionObserver' in window) {
- let options = {
- rootMargin: `${top}px ${right}px ${bottom}px ${left}px`,
- threshold: Array.from({ length: steps }, (_, i) => i / (steps - 1))
- };
-
- observer = new IntersectionObserver(intersectPercent, options);
- observer.observe(element);
- }
+ if ("IntersectionObserver" in window) {
+ let options = {
+ rootMargin: `${top}px ${right}px ${bottom}px ${left}px`,
+ threshold: Array.from({ length: steps }, (_, i) => i / (steps - 1)),
+ };
+
+ observer = new IntersectionObserver(intersectPercent, options);
+ observer.observe(element);
+ }
});
onDestroy(() => observer?.unobserve(element));