本质上,我正在制作一个幻灯片项目,其中每个“幻灯片”都是使用 <svelte:component this={currentSelection.component} />
. 每张幻灯片都需要逐个组件的自定义输入和输出转换。我希望下一张幻灯片在当前幻灯片完成转换时“等待”,但是,如 svelte 文档中所述:
与 transition: 不同,使用 in: 和 out: 应用的转换不是双向的——如果在转换进行时块被淘汰,则in 转换将继续与 out 转换一起“播放”,而不是反转。如果退出转换被中止,转换将从头开始。
有没有一种明智的方法可以让下一张幻灯片“等待”直到当前幻灯片完成其结尾过渡?
REPL的玩具示例
为后代发布的玩具代码:
//App.svelte
<script>
import RedThing from './RedThing.svelte';
import GreenThing from './GreenThing.svelte';
import BlueThing from './BlueThing.svelte';
const slides = [
RedThing,
BlueThing,
GreenThing
];
let currentComponent = 0;
const prev = () => currentComponent--;
const next = () => currentComponent++;
</script>
<button on:click={prev}>Prev</button><button on:click={next}>Next</button>
<div>
<svelte:component this={slides[currentComponent]}/>
</div>
//RedThing.svelte
<script>
import { fly, slide } from 'svelte/transition';
</script>
<style>
div { color: red; }
</style>
<div in:fly out:slide>red thing</div>
//GreenThing.svelte
<script>
import { fade, slide } from 'svelte/transition';
</script>
<style>
div { color: green; }
</style>
<div in:slide out:fade>green thing</div>
//BlueThing.svelte
<script>
import { scale, fade } from 'svelte/transition';
</script>
<style>
div { color: blue; }
</style>
<div in:scale out:fade>blue thing</div>
编辑:我应该添加一个复杂性——我正在通过 sapper 锚标记驱动组件遍历,这些锚标记负责组件的创建/销毁。换句话说:
<a href={prev} id="previous-button">Previous</a>
<a href={next} id="next-button">Next</a>
<div>
<svelte:component this={slides[currentComponent]}/>
</div>
我不确定这是否有区别?