【发布时间】:2022-01-31 23:49:31
【问题描述】:
我正在尝试在 Svelte 中构建一个简单的过渡,其中我的卡片会在页面加载时进行动画处理。我已经关注this answer 让它正确触发onMount,所以没关系。但是,过渡本身似乎“跳”到结尾太快了,并跳过了最后几帧。
GIF of problem running on localhost.
奇怪的是,当我将相同的代码复制并粘贴到REPL 中时,视觉错误似乎已修复。我什至下载了REPL并在本地运行,但仍然出现错误。
这里是代码。
<script>
import { fly } from 'svelte/transition';
import { onMount } from 'svelte';
const contents = [
{
id: 1,
},
{
id: 2,
},
{
id: 3,
},
];
let ready = false;
onMount(() => (ready = true));
</script>
<main>
<div class="topBar" />
<div class="container">
{#if ready}
{#each contents as content, i}
<div
class="transCard"
transition:fly={{ y: 80, duration: 1000, delay: i * 200 }}
/>
{/each}
{/if}
</div>
</main>
<style>
main {
background: white;
width: 100vw;
height: 100vh;
overflow-y: auto;
overflow-x: hidden;
}
.container {
display: flex;
flex-direction: column;
gap: 16px;
padding: 16px;
overflow: hidden;
margin-top: 80px;
}
.topBar {
width: 100vw;
height: 80px;
background: black;
position: fixed;
top: 0;
left: 0;
z-index: 9;
}
.transCard {
width: 100%;
height: 200px;
background: gray;
}
</style>
【问题讨论】:
-
main 是视口的大小,所以我期望位置是固定的或绝对的,左和顶部为 0。我认为跳跃可能是由容器引起的,滚动位置也是意料之外的在 gif 中,不知道是什么导致了这种行为。
-
嗯,试过了,好像没用。
标签: html css svelte svelte-transition