{"id":1409,"date":"2019-09-28T22:31:02","date_gmt":"2019-09-28T14:31:02","guid":{"rendered":"https:\/\/www.develop-note.com\/blog\/?p=1409"},"modified":"2022-02-17T15:02:32","modified_gmt":"2022-02-17T07:02:32","slug":"2020ironman-svelte-crossfade","status":"publish","type":"post","link":"https:\/\/www.develop-note.com\/blog\/2019\/09\/28\/2020ironman-svelte-crossfade\/","title":{"rendered":"\u7b2c\u5341\u4e00\u5c46\u9435\u4eba\u8cfd \u524d\u7aef\u5de5\u7a0b\u5e2b\u7684\u53e6\u4e00\u500b\u9078\u64c7 svelte DAY27- \u904e\u5834\u52d5\u756b (\u56db)"},"content":{"rendered":"<h1>crossfade<\/h1>\n<p>\u6628\u5929\u4ecb\u7d39\u5b8c<a href=\"https:\/\/www.develop-note.com\/blog\/2019\/09\/27\/2020ironman-svelte-draw\/\" title=\"draw\">draw<\/a>\uff0c\u5c31\u662f\u900f\u904esvg\u7684path\u7e6a\u51fa\u4e00\u500b\u904e\u5834\u52d5\u756b\uff0c\u4eca\u5929\u4f86\u8ddf\u5927\u5bb6\u5206\u4eab\u4e00\u4e0b<code>crossfade<\/code>\u3002<!--more--><\/p>\n<h2>crossfade \u662f\u751a\u9ebc<\/h2>\n<p>\u4e4b\u524d\u6709\u63d0\u5230\u4e00\u500b<a href=\"https:\/\/www.develop-note.com\/blog\/2019\/09\/25\/2020ironman-svelte-transitions\/\" title=\"fade\">fade<\/a>\uff0c\u4e0d\u77e5\u9053\u8b80\u8005\u5011\u9084\u8a18\u4e0d\u8a18\u5f97\uff0c\u90a3\u500bfade\u5c31\u662f\u6de1\u5165\u6de1\u51fa\u7684\u904e\u5834\u52d5\u756b\uff0c\u800c <code>crossfade<\/code> \u53ef\u4ee5\u505a\u5230\u7684\u662f\u5728\u5169\u7a2e\u904e\u5834\u52d5\u756b\u4e4b\u9593\u5448\u73fe\uff0c\u800c\u4e0d\u50cf\u4e4b\u524d\u8aaa\u7684\u8a71\u6d88\u5931\u3002<\/p>\n<h2>crossfade \u600e\u9ebc\u7528<\/h2>\n<p>\u4ecb\u7d39\u5b8c <code>crossfade<\/code> \u7684\u6982\u5ff5\u5f8c\u73fe\u5728\u4f86\u8aaa\u660e\u8981\u5982\u4f55\u4f7f\u7528\uff0c\u9019\u88e1\u6211\u5011\u7528\u4e00\u500b todolist \u4f86\u4ecb\u7d39\uff0c\u8acb\u5927\u5bb6\u5148\u770b\u770b\u4e0b\u9762\u7684\u7a0b\u5f0f\u78bc\u3002<\/p>\n<pre><code class=\"language-xml\">&lt;script&gt;\n    import { quintOut } from &#039;svelte\/easing&#039;;\n    import { crossfade } from &#039;svelte\/transition&#039;;\n\n    const [send, receive] = crossfade({\n        duration: d =&gt; Math.sqrt(d * 200),\n\n        fallback(node, params) {\n            const style = getComputedStyle(node);\n            const transform = style.transform === &#039;none&#039; ? &#039;&#039; : style.transform;\n\n            return {\n                duration: 600,\n                easing: quintOut,\n                css: t =&gt; `\n                    transform: ${transform} scale(${t});\n                    opacity: ${t}\n                `\n            };\n        }\n    });\n\n    let uid = 1;\n\n    let todos = [\n        { id: uid++, done: false, description: &#039;write some docs&#039; },\n        { id: uid++, done: false, description: &#039;start writing blog post&#039; },\n        { id: uid++, done: true,  description: &#039;buy some milk&#039; },\n        { id: uid++, done: false, description: &#039;mow the lawn&#039; },\n        { id: uid++, done: false, description: &#039;feed the turtle&#039; },\n        { id: uid++, done: false, description: &#039;fix some bugs&#039; },\n    ];\n\n    function add(input) {\n        const todo = {\n            id: uid++,\n            done: false,\n            description: input.value\n        };\n\n        todos = [todo, ...todos];\n        input.value = &#039;&#039;;\n    }\n\n    function remove(todo) {\n        todos = todos.filter(t =&gt; t !== todo);\n    }\n\n    function mark(todo, done) {\n        todo.done = done;\n        remove(todo);\n        todos = todos.concat(todo);\n    }\n&lt;\/script&gt;\n\n&lt;div class=&#039;board&#039;&gt;\n    &lt;input\n        placeholder=&quot;what needs to be done?&quot;\n        on:keydown={e =&gt; e.which === 13 &amp;&amp; add(e.target)}\n    &gt;\n\n    &lt;div class=&#039;left&#039;&gt;\n        &lt;h2&gt;todo&lt;\/h2&gt;\n        {#each todos.filter(t =&gt; !t.done) as todo (todo.id)}\n            &lt;label\n                            in:receive=&quot;{{key: todo.id}}&quot;\n                            out:send=&quot;{{key: todo.id}}&quot;\n                         &gt;\n                &lt;input type=checkbox on:change={() =&gt; mark(todo, true)}&gt;\n                {todo.description}\n                &lt;button on:click=&quot;{() =&gt; remove(todo)}&quot;&gt;remove&lt;\/button&gt;\n            &lt;\/label&gt;\n        {\/each}\n    &lt;\/div&gt;\n\n    &lt;div class=&#039;right&#039;&gt;\n        &lt;h2&gt;done&lt;\/h2&gt;\n        {#each todos.filter(t =&gt; t.done) as todo (todo.id)}\n            &lt;label class=&quot;done&quot;\n                            in:receive=&quot;{{key: todo.id}}&quot;\n                            out:send=&quot;{{key: todo.id}}&quot;\n                         &gt;\n                &lt;input type=checkbox checked on:change={() =&gt; mark(todo, false)}&gt;\n                {todo.description}\n                &lt;button on:click=&quot;{() =&gt; remove(todo)}&quot;&gt;remove&lt;\/button&gt;\n            &lt;\/label&gt;\n        {\/each}\n    &lt;\/div&gt;\n&lt;\/div&gt;\n\n&lt;style&gt;\n    .board {\n        display: grid;\n        grid-template-columns: 1fr 1fr;\n        grid-gap: 1em;\n        max-width: 36em;\n        margin: 0 auto;\n    }\n\n    .board &gt; input {\n        font-size: 1.4em;\n        grid-column: 1\/3;\n    }\n\n    h2 {\n        font-size: 2em;\n        font-weight: 200;\n        user-select: none;\n        margin: 0 0 0.5em 0;\n    }\n\n    label {\n        position: relative;\n        line-height: 1.2;\n        padding: 0.5em 2.5em 0.5em 2em;\n        margin: 0 0 0.5em 0;\n        border-radius: 2px;\n        user-select: none;\n        border: 1px solid hsl(240, 8%, 70%);\n        background-color:hsl(240, 8%, 93%);\n        color: #333;\n    }\n\n    input[type=&quot;checkbox&quot;] {\n        position: absolute;\n        left: 0.5em;\n        top: 0.6em;\n        margin: 0;\n    }\n\n    .done {\n        border: 1px solid hsl(240, 8%, 90%);\n        background-color:hsl(240, 8%, 98%);\n    }\n\n    button {\n        position: absolute;\n        top: 0;\n        right: 0.2em;\n        width: 2em;\n        height: 100%;\n        background: no-repeat 50% 50% url(&quot;data:image\/svg+xml,%3Csvg xmlns=&#039;http:\/\/www.w3.org\/2000\/svg&#039; viewBox=&#039;0 0 24 24&#039;%3E%3Cpath fill=&#039;%23676778&#039; d=&#039;M12,2C17.53,2 22,6.47 22,12C22,17.53 17.53,22 12,22C6.47,22 2,17.53 2,12C2,6.47 6.47,2 12,2M17,7H14.5L13.5,6H10.5L9.5,7H7V9H17V7M9,18H15A1,1 0 0,0 16,17V10H8V17A1,1 0 0,0 9,18Z&#039;%3E%3C\/path%3E%3C\/svg%3E&quot;);\n        background-size: 1.4em 1.4em;\n        border: none;\n        opacity: 0;\n        transition: opacity 0.2s;\n        text-indent: -9999px;\n        cursor: pointer;\n    }\n\n    label:hover button {\n        opacity: 1;\n    }\n&lt;\/style&gt;<\/code><\/pre>\n<p>\u9019\u908a\u8aaa\u660e\u4e00\u4e0b\u76f8\u95dc\u7684\u5167\u5bb9\uff0c\u9019\u88e1\u8981\u6ce8\u610f\u7684\u662f\u4e0b\u9762\u5e7e\u9ede\u3002<\/p>\n<h3>send receive<\/h3>\n<p>\u5728\u547c\u53eb <code>crossfade<\/code> \u65b9\u6cd5\u6642\u6703\u6709\u56de\u50b3\u503csend\u8ddfreceive\uff0c\u7136\u5f8c\u5728html\u4e0a\u9762\u4e5f\u8a18\u5f97\u8981\u6709\u5169\u500b\u5143\u7d20\u5206\u5225\u6709\u5176send\u8ddfreceive\uff0c\u9019\u4e3b\u8981\u662f\u7576\u72c0\u614b\u8b8a\u66f4\u6642\uff0c\u7269\u4ef6\u6703\u7531A\u5143\u7d20\u8dd1\u5230B\u5143\u7d20\u7684\u4f4d\u7f6e\u3002<\/p>\n<h3>fallback<\/h3>\n<p>\u547c\u53eb <code>crossfade<\/code> \u6642\u8981\u50b3\u5165\u4e00\u500b\u53c3\u6578\u4ed6\u7684\u7528\u9014\u662f\u7576\u7269\u4ef6\u6d88\u5931\u6642\u8981\u505a\u7684\u8655\u7f6e\u3002<\/p>\n<h2>\u5c0f\u7d50<\/h2>\n<p>\u4eca\u5929\u8ddf\u5927\u5bb6\u4ecb\u7d39\u5982\u4f55\u7528svelte\u7684crossfade\u88fd\u4f5c\u4e00\u500btodolist\uff0c\u96d6\u7136\u5167\u5bb9\u6709\u9ede\u7e41\u7463\uff0c\u4f46\u662f\u53ea\u8981\u638c\u63e1\u4e86\u61c9\u8a72\u53ef\u4ee5\u5f97\u5fc3\u61c9\u624b\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>crossfade \u6628\u5929\u4ecb\u7d39\u5b8cdraw\uff0c\u5c31\u662f\u900f\u904esvg\u7684path\u7e6a\u51fa\u4e00\u500b\u904e\u5834\u52d5\u756b\uff0c\u4eca\u5929\u4f86\u8ddf\u5927\u5bb6\u5206\u4eab\u4e00\u4e0bcros &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.develop-note.com\/blog\/2019\/09\/28\/2020ironman-svelte-crossfade\/\" class=\"more-link\">\u95b1\u8b80\u5168\u6587<span class=\"screen-reader-text\">\u3008\u7b2c\u5341\u4e00\u5c46\u9435\u4eba\u8cfd \u524d\u7aef\u5de5\u7a0b\u5e2b\u7684\u53e6\u4e00\u500b\u9078\u64c7 svelte DAY27- \u904e\u5834\u52d5\u756b (\u56db)\u3009<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"_exactmetrics_skip_tracking":false,"_exactmetrics_sitenote_active":false,"_exactmetrics_sitenote_note":"","_exactmetrics_sitenote_category":0,"footnotes":""},"categories":[2],"tags":[160,79],"class_list":["post-1409","post","type-post","status-publish","format-standard","hentry","category-develop","tag-2019ironman","tag-svelte"],"_links":{"self":[{"href":"https:\/\/www.develop-note.com\/blog\/wp-json\/wp\/v2\/posts\/1409","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.develop-note.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.develop-note.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.develop-note.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.develop-note.com\/blog\/wp-json\/wp\/v2\/comments?post=1409"}],"version-history":[{"count":9,"href":"https:\/\/www.develop-note.com\/blog\/wp-json\/wp\/v2\/posts\/1409\/revisions"}],"predecessor-version":[{"id":2998,"href":"https:\/\/www.develop-note.com\/blog\/wp-json\/wp\/v2\/posts\/1409\/revisions\/2998"}],"wp:attachment":[{"href":"https:\/\/www.develop-note.com\/blog\/wp-json\/wp\/v2\/media?parent=1409"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.develop-note.com\/blog\/wp-json\/wp\/v2\/categories?post=1409"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.develop-note.com\/blog\/wp-json\/wp\/v2\/tags?post=1409"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}