refactor: rethink ProcessStep transition + use tick in transitions

This commit is contained in:
2024-08-05 16:28:14 +02:00
parent 1cc143ef27
commit 191e1ef847
3 changed files with 46 additions and 46 deletions

View File

@@ -9,13 +9,11 @@ import { quartOut } from './easings'
export const scaleFade = (node: HTMLElement, {
scale = [0.7, 1],
opacity = [1, 0],
x = null,
x = [0, 0],
delay = 0,
duration = 1,
duration = 0.75,
}): TransitionConfig => {
return {
css: () => {
animate(node, {
const anim = animate(node, {
scale,
opacity,
x,
@@ -26,7 +24,10 @@ export const scaleFade = (node: HTMLElement, {
delay,
})
return null
return {
duration: anim.duration * 1000,
tick: (t) => {
anim.currentTime = t
}
}
}
@@ -42,9 +43,7 @@ export const revealSplit = (node: HTMLElement, {
duration = 1,
delay = 0,
}): TransitionConfig => {
return {
css: () => {
animate(node.querySelectorAll(children), {
const anim = animate(node.querySelectorAll(children), {
opacity,
y,
z: 0,
@@ -54,7 +53,10 @@ export const revealSplit = (node: HTMLElement, {
delay: stagger(0.04, { start: delay }),
})
return null
return {
duration: anim.duration * 1000,
tick: (t) => {
anim.currentTime = t
}
}
}

View File

@@ -3,18 +3,18 @@
</style>
<script lang="ts">
import { scale } from 'svelte/transition'
import { quartOut } from 'svelte/easing'
import { scaleFade } from '$animations/transitions'
// Components
import Image from '$components/atoms/Image.svelte'
import { getAssetUrlKey } from '$utils/api'
let {
index,
text,
image,
video,
}: {
index: number
text: string
image?: any
video?: any
@@ -25,9 +25,8 @@
<div
class="step grid"
style:--index={index}
in:scaleFade|local={{ scale: [1.1, 1], opacity: [0, 1], x: [20, 0], delay: 0.2 }}
out:scaleFade|local={{ scale: [1, 0.9], opacity: [1, 0], x: [0, -20] }}
out:scale={{ start: 0.9, duration: 750, easing: quartOut }}
>
{#if image || video}
<div class="media">

View File

@@ -26,7 +26,8 @@
let innerWidth = $state<number>()
let photosGridEl: HTMLElement
let photosGridParallax = $state<number>()
let currentStep = $state(0)
let currentStepIndex = $state(0)
const currentStep = $derived(data.about.process_steps[currentStepIndex])
let emailCopied = $state<string>()
let emailCopiedTimeout: ReturnType<typeof setTimeout> | number
@@ -312,13 +313,13 @@
<ol>
{#each data.about.process_steps as { title }, index}
<li class:is-active={index === currentStep}>
<li class:is-active={index === currentStepIndex}>
<a
class="title-big"
href="#step-{index + 1}"
onclick={(event) => {
event.preventDefault()
currentStep = index
currentStepIndex = index
sendEvent('aboutStepSwitch')
}}
>
@@ -330,18 +331,16 @@
</aside>
<div class="steps">
{#each data.about.process_steps as { text, image, video_mp4, video_webm }, index}
{#if index === currentStep}
{#key currentStep}
<ProcessStep
{index} {text}
image={image ?? undefined}
text={currentStep.text}
image={currentStep.image}
video={{
mp4: video_mp4?.id,
webm: video_webm?.id
mp4: currentStep.video_mp4?.id,
webm: currentStep.video_webm?.id
}}
/>
{/if}
{/each}
{/key}
</div>
</div>
</section>