admin管理员组文章数量:1335871
I'm building drag'n'drop ponent for svelte and would like to add animations. I have adapted code from another ponent, but I cannot make it to work, could you help me pinpoint where the problem is? I don't understand error im getting. here is working REPL
/repl/acc2c90db2054d89b210f23c026c525e?version=3.16.7
error shows when I paste:
in:receive={{ key: index }}
out:send={{ key: index }}
animate:flip={{ duration: 300 }}
into line 130 of ponent in REPL
following error message i get: "An element that use the animate directive must be the immediate child of a keyed each block (132:8)"
i have tried to remove "wrap" div to move animate one as "direct child" of #each but it didnt help
{#if list && list.length}
<div class="cont">
{#each list as item, index}
<div class="wrap">
<div
data-index={index}
id={index}
on:dragstart={() => { return false }}
on:touchstart={handleMousedown}
on:touchmove={handleMousemove}
on:touchend={handleMouseup}
on:mousedown={handleMousedown}
on:mousemove={handleMousemove}
on:mouseover={HandleMouseover}
in:receive={{ key: index }}
out:send={{ key: index }}
animate:flip={{ duration: 300 }}
class="tobedragged {((index == movingIndex) && moving) ? 'ghost' : ''}" style="top: {m.y}px; left: {m.x}px;">
list index: {index}<br>
{item}
<slot {item} {index} />
</div>
</div>
{/each}
</div>
{/if}
I'm building drag'n'drop ponent for svelte and would like to add animations. I have adapted code from another ponent, but I cannot make it to work, could you help me pinpoint where the problem is? I don't understand error im getting. here is working REPL
https://svelte.dev/repl/acc2c90db2054d89b210f23c026c525e?version=3.16.7
error shows when I paste:
in:receive={{ key: index }}
out:send={{ key: index }}
animate:flip={{ duration: 300 }}
into line 130 of ponent in REPL
following error message i get: "An element that use the animate directive must be the immediate child of a keyed each block (132:8)"
i have tried to remove "wrap" div to move animate one as "direct child" of #each but it didnt help
{#if list && list.length}
<div class="cont">
{#each list as item, index}
<div class="wrap">
<div
data-index={index}
id={index}
on:dragstart={() => { return false }}
on:touchstart={handleMousedown}
on:touchmove={handleMousemove}
on:touchend={handleMouseup}
on:mousedown={handleMousedown}
on:mousemove={handleMousemove}
on:mouseover={HandleMouseover}
in:receive={{ key: index }}
out:send={{ key: index }}
animate:flip={{ duration: 300 }}
class="tobedragged {((index == movingIndex) && moving) ? 'ghost' : ''}" style="top: {m.y}px; left: {m.x}px;">
list index: {index}<br>
{item}
<slot {item} {index} />
</div>
</div>
{/each}
</div>
{/if}
Share
Improve this question
asked Dec 27, 2019 at 8:21
toHotoHo
4387 silver badges28 bronze badges
1 Answer
Reset to default 7What you have is an indexed each block, which won't work. A keyed each block looks like this. (preferably with a proper key)
{#each list as item, index (item)}
Also, I'm not sure you need "receive" and "send" for what you're trying to acplish. The animate directive should be enough.
Have a look here https://svelte.dev/repl/2a310d0e23954ee591f941ff57616364?version=3.16.7
本文标签: javascriptAnimations in svelte componentStack Overflow
版权声明:本文标题:javascript - Animations in svelte component - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742397628a2467243.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论