How to animate card fade in and fade out inplace in svelte - Stack Overflow

How would I create the following animation in svelte?what I am trying to do:I have a two div elements

How would I create the following animation in svelte?

what I am trying to do: I have a two div elements. When I click on a button, firs div element fades out while the second div element fades in. Both the div elements are at the same position. So it looks like when one is fading out, the other card is fading in to take its place. Example:

What I have already tried: Demo here: /u09gz5ytcs9rl7i

As you can see in the demo, the other card fades in but it is below the first card, and as the first card disappears it snaps in to its place.

How would I create the following animation in svelte?

what I am trying to do: I have a two div elements. When I click on a button, firs div element fades out while the second div element fades in. Both the div elements are at the same position. So it looks like when one is fading out, the other card is fading in to take its place. Example: https://playcode.io/2226396

What I have already tried: Demo here: https://www.sveltelab.dev/u09gz5ytcs9rl7i

As you can see in the demo, the other card fades in but it is below the first card, and as the first card disappears it snaps in to its place.

Share Improve this question asked Jan 17 at 16:47 montemonte 1,8932 gold badges17 silver badges39 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 1

This happens because the first element is still in place when the second element is rendered. The first element will only leave the DOM after its animation ends, and the second is rendered before its animation starts.

What you could do is make both elements occupy the same space in the div, while making sure there is a delay between the animations:

<CardContent>

    {#if btn}
        <div transition:fade={{ duration: 1000, delay: btn ? 1000 : 0 }} class="column-start-1">
            <Card>
                <CardContent>
                    First Card
                </CardContent>
            </Card>
        </div>
    {:else}
        <div transition:fade={{ duration: 1000, delay: btn ? 0 : 1000 }} class="column-start-1">
            <Card>
                <CardContent>
                    Second Card
                </CardContent>
            </Card>
        </div>
    {/if}
    
</CardContent>

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745354373a4624027.html

相关推荐

  • How to animate card fade in and fade out inplace in svelte - Stack Overflow

    How would I create the following animation in svelte?what I am trying to do:I have a two div elements

    6小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信