diff --git a/src/lib/components/cards/CardFan.svelte b/src/lib/components/cards/CardFan.svelte new file mode 100644 index 0000000..4fe661f --- /dev/null +++ b/src/lib/components/cards/CardFan.svelte @@ -0,0 +1,49 @@ + + +
+ + {#each displayCards as card, i (i)} + {@const fanOffset = (totalCards - 1 - i) * 75} + +
+ Card {i + 1} +
+ {/each} +
diff --git a/src/lib/components/cards/FrontBack.svelte b/src/lib/components/cards/FrontBack.svelte index 1207668..54ff884 100644 --- a/src/lib/components/cards/FrontBack.svelte +++ b/src/lib/components/cards/FrontBack.svelte @@ -11,34 +11,22 @@ let fanned = $state(false); const cardDeck: Attachment = (node) => { - const observer = new IntersectionObserver( - (entries) => { - for (const entry of entries) { - fanned = entry.isIntersecting; - } - }, - { rootMargin: "-40% 0px -40% 0px", threshold: 0 } - ); - - observer.observe(node); - - const onEnter = () => (fanned = true); - const onLeave = () => (fanned = false); - - node.addEventListener("mouseenter", onEnter); - node.addEventListener("mouseleave", onLeave); - - return () => { - observer.disconnect(); - node.removeEventListener("mouseenter", onEnter); - node.removeEventListener("mouseleave", onLeave); + const check = () => { + const rect = node.getBoundingClientRect(); + const cardCenter = rect.top + rect.height / 2; + fanned = cardCenter <= window.innerHeight / 2; }; + + window.addEventListener("scroll", check, { passive: true }); + check(); + + return () => window.removeEventListener("scroll", check); }; diff --git a/src/routes/cards/+page.svelte b/src/routes/cards/+page.svelte index b8ce9d4..8d88c0f 100644 --- a/src/routes/cards/+page.svelte +++ b/src/routes/cards/+page.svelte @@ -1,22 +1,35 @@ BIBDLE Cards -
Collectible Bible Verse Trading Cards
-
+
Collectible Bible Verse Trading Cards
+
- - -
+

Card Fan Demo

+

Cards will fan out after a few seconds...

+
+ +
+
+ +