我有一个像这样构建的组件
<ul class="space-y-3 flex-col items-end justify-end absolute bottom-6 left-6 right-6 overflow-hidden">
{#each $chatDisplayQueue as chatEvent (chatEvent.id)}
<div in:fly={{y:150,duration: 200}} out:fade={{duration: 200}} animate:flip={{duration: 200}}>
<ChatMessage event={chatEvent}/>
</div>
{/each}
</ul>请注意,我有一个过渡和一个动画。in变换可以工作,但是out变换不能工作,如果翻转动画在那里:/有一种方法可以正确地做到这一点,以便变换和动画都工作吗?提前感谢
发布于 2021-07-08 05:40:53
如果我没弄错你的问题,你想要这样的东西:
<script>
import {flip} from 'svelte/animate';
import { fly } from 'svelte/transition';
let horizontal = false;
let next = 1;
let list = [];
const addItem = () => list = [next++, ...list];
const removeItem = number => list = list.filter(n => n !== number);
const options = {};
</script>
<label>
Horizontal
<input type="checkbox" bind:checked={horizontal} />
</label>
<button on:click={addItem}>Add</button>
{#each list as n (n)}
<div transition:fly="{{ y: 200, duration: 2000 }}" animate:flip={options} class:horizontal class="container">
<button on:click={() => removeItem(n)}>{n}</button>
</div>
{/each}
<style>
.container {
width: fit-content; /* a fix */
}
.horizontal {
display: inline-block;
margin-left: 10px;
}
</style>
来源:url
https://stackoverflow.com/questions/68273921
复制相似问题