From fb03377d77a8f00b92cac51792bb8f3391a06960 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fe=CC=81lix=20Pe=CC=81ault?= Date: Tue, 27 Sep 2022 10:09:36 +0200 Subject: [PATCH] Globe: Use Svelte transition using Motion to reveal current location Split text --- src/animations/transitions.ts | 43 +++++++++++++++++-- .../organisms/InteractiveGlobe.svelte | 14 ++---- 2 files changed, 42 insertions(+), 15 deletions(-) diff --git a/src/animations/transitions.ts b/src/animations/transitions.ts index 350c4e4..3f3cd38 100644 --- a/src/animations/transitions.ts +++ b/src/animations/transitions.ts @@ -1,13 +1,18 @@ -import { animate } from 'motion' +import { animate, stagger } from 'motion' +import type { TransitionConfig } from 'svelte/transition' import { quartOut } from './easings' + +/** + * Scale and fade + */ export const scaleFade = (node: HTMLElement, { - delay = 0, - duration = 1, scale = [0.7, 1], opacity = [1, 0], x = null, -}) => { + delay = 0, + duration = 1, +}): TransitionConfig => { return { css: () => { animate(node, { @@ -20,6 +25,36 @@ export const scaleFade = (node: HTMLElement, { duration, delay, }) + + return null + } + } +} + + +/** + * Scale and fade split text + */ +export const revealSplit = (node: HTMLElement, { + opacity = [0, 1], + y = ['110%', '0%'], + children = '.char', + duration = 1, + delay = 0, +}): TransitionConfig => { + return { + css: () => { + animate(node.querySelectorAll(children), { + opacity, + y, + z: 0, + }, { + easing: quartOut, + duration, + delay: stagger(0.04, { start: delay }), + }) + + return null } } } \ No newline at end of file diff --git a/src/components/organisms/InteractiveGlobe.svelte b/src/components/organisms/InteractiveGlobe.svelte index c8245bc..a8bf599 100644 --- a/src/components/organisms/InteractiveGlobe.svelte +++ b/src/components/organisms/InteractiveGlobe.svelte @@ -8,7 +8,7 @@ import { quartOut } from 'svelte/easing' import { Globe, type Marker } from '$modules/globe' import { getRandomItem, debounce } from '$utils/functions' - import reveal from '$animations/reveal' + import { revealSplit } from '$animations/transitions' // Components import SplitText from '$components/SplitText.svelte' @@ -145,16 +145,8 @@ {#if hoveredMarker}