Skip to content
This repository has been archived by the owner on Jan 11, 2023. It is now read-only.

Simple fade-out/fade-in route transition in sapper #902

Open
rchrdnsh opened this issue Sep 17, 2019 · 9 comments
Open

Simple fade-out/fade-in route transition in sapper #902

rchrdnsh opened this issue Sep 17, 2019 · 9 comments

Comments

@rchrdnsh
Copy link

rchrdnsh commented Sep 17, 2019

Just spun up an instance of the the starter svelte template and I'm trying to add a simple fade-out/fade-in route transition from route to route. I did this to the _layout.svelte component:

<script>
  import Nav from '../components/Nav.svelte';

  export let segment;

  import { fade } from 'svelte/transition';
  let visible = true;
</script>

<style>
  main {
    position: relative;
    max-width: 56em;
    background-color: rgb(197, 197, 197);
    padding: 2em;
    margin: 0 auto;
    box-sizing: border-box:
  }
</style>

<Nav {segment}/>

{#if visible}
  <main>
    <slot></slot>
  </main>	
{/if}

...and it did not work, so I'm wondering what the correct approach would be to make this work. I got this idea from the svelte 3 tutorial, and I also tried wrapping only the <slot> and that did not seem to work either.

Thank you! 🤗

@swyxio
Copy link

swyxio commented Sep 18, 2019

@swyxio

This comment has been minimized.

@swyxio
Copy link

swyxio commented Sep 18, 2019

@swyxio
Copy link

swyxio commented Sep 18, 2019

note to self, nestedtransitions dont exist in v3 anymore

@rchrdnsh
Copy link
Author

hmmmm...so vue does it like this:

<main>
  <transition name="fade">
    <router-view name="app-content"></router-view>
  </transition>
</main>

...with a little bit of css to define the behavior of the fade:

.fade-enter-active, .fade-leave-active {
  transition-property: opacity;
  transition-duration: 0.25s;
}

.fade-enter-active {
  transition-delay: 0.25s;
}

.fade-enter, .fade-leave-active {
  opacity: 0
}

...and that is it. So simple and elegant and awesome and easy and lovely in general. :-)

I would hope that svelte/sapper's implementation would be about this level of simple, as that's kind of the point of svelte/sapper, no?

@swyxio
Copy link

swyxio commented Sep 18, 2019

sapper is a newer project and route transitions are less well documented. i suggest making your own transition component with the api you want and sharing with everyone. we’re all learning here. in particular check the svelte tutorial for how the fade transition works under the hood

@rchrdnsh
Copy link
Author

hmmmm...never done something like that before. Not really sure where I would start, to be honest 🤔

@maxmilton
Copy link

This article might be of some help: https://dev.to/buhrmi/svelte-component-transitions-5ie.

@benmccann
Copy link
Member

See also https://github.com/sveltejs/sapper/issues/814

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants