Svelte在每个#each块上的过渡效果

huangapple go评论72阅读模式
英文:

Svelte transition on an #each block

问题

使用Svelte,我正在尝试在{#each}块中实现飞入过渡。这是否可能?

请参阅下面的重要代码,也可以在此REPL中找到:

{#if visible}
  {@const i=1000}
  <div in:fly={{ y: 50, duration:i, delay: 100, easing: cubicOut }}>
    test234
  </div>
  <div in:fly={{ y: 50, duration:i, delay: 100, easing: cubicOut }}>
    test234
  </div>
  {#each values as value (value.i)}
    <div  in:fly={{ y: 50, duration: value.i*300, delay: 100, easing: cubicOut }}>
      {value.val} and i is {value.i}
    </div>
  {/each}
{/if}
英文:

Using svelte I am trying to implement a fly transition in an {#each} block. Is that possible?

See below the important code that can be also found in this REPL

{#if visible}
  {@const i=1000}
  &lt;div in:fly={{ y: 50, duration:i, delay: 100, easing: cubicOut }}&gt;
    test234
  &lt;/div&gt;
  &lt;div in:fly={{ y: 50, duration:i, delay: 100, easing: cubicOut }}&gt;
    test234
  &lt;/div&gt;
  {#each values as value (value.i)}
    &lt;div  in:fly={{ y: 50, duration: value.i*300, delay: 100, easing: cubicOut }}&gt;
      {value.val} and i is {value.i}
    &lt;/div&gt;
  {/each}
{/if}

答案1

得分: 1

自 Svelte 4 开始,默认情况下,过渡是局部的。添加 |global 标志将使其工作(而不是映射值,可以使用 #each 块的索引)。

{#each values as value, index}
  <div in:fly|global={{ y: 50, duration: index*300, delay: 100, easing: cubicOut }}>
    {value.val} and i is {value.i}
  </div>
{/each}
英文:

Since Svelte 4 Transitions are local by default
Adding the |global flag will make it work (and instead of mapping the values, the index of the #each block could be used)

  {#each values as value, index}	
    &lt;div  in:fly|global={{ y: 50, duration: index*300, delay: 100, easing: cubicOut }}&gt;
      {value.val} and i is {value.i}
    &lt;/div&gt;
  {/each}

huangapple
  • 本文由 发表于 2023年7月11日 14:34:22
  • 转载请务必保留本文链接:https://go.coder-hub.com/76659237.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定