I'm developing a Svelte UI with full page navigation using svelte-spa-router. I'm facing the case where the UX designer defined the transition between page "per transition" and not per page has it's meant to be in Svelte (AFAIK).
E.g. in this UX page B1 out transition would :
- disappeared instantly when going back to the home page A ;
- slide left when going to C1 ;
- dissolve when going to B2.
The UX actually makes sense because B1/B2, C1/C2 are similar but treats the same subject from a different point of view.
Svelte transition are working great but are defined per component, with a in transition and an out transition.
I tried leveraging the fact that transition property could be object and reactive.
<script>
import { fade } from "svelte/transition";
let page = "A";
let duration = 0;
function goto(dest) {
if(dest == "A" || page == "A") {
duration = 0;
} else {
duration = 400;
}
page = dest;
}
</script>
{#if page == "A"}
<section class="A" transition:fade={{duration: duration}}>
<h1>Page A</h1>
<nav on:click={e => goto("B1")}>Goto B1</nav>
<nav on:click={e => goto("B2")}>Goto B2</nav>
</section>
{:else if page == "B1"}
<section class="B1" transition:fade={{duration: duration}}>
<h1>Page B1</h1>
<nav on:click={e => goto("A")}>Goto Back</nav>
<nav on:click={e => goto("B2")}>Goto B2</nav>
</section>
{:else if page == "B2"}
<section class="B2" transition:fade={{duration: duration}}>
<h1>Page B2</h1>
<nav on:click={e => goto("A")}>Goto Back</nav>
<nav on:click={e => goto("B1")}>Goto B1</nav>
</section>
{/if}
<style>
section {
position: absolute;
width: 500px;
height: 500px;
}
section.A {
background: pink;
}
section.B1 {
background: blue;
}
section.B2 {
background: yellow;
}
</style>
But I cannot figure out how to change the transition effect (maybe a custom transition function ?). Moreover, this solution seems very complicated, time consuming and could really turn to a ball of spaghetti in a more complex UX.
In addition, in svelte-spa-router I did not found a way to know where I'm coming from (i.e. the prevision location) to manage the transition accordingly.
Any thoughts ?
