<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: PhanDangKhoa96</title>
    <description>The latest articles on Forem by PhanDangKhoa96 (@phandangkhoa96).</description>
    <link>https://forem.com/phandangkhoa96</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F927661%2F9c8ce94b-6dfa-4237-bce5-94a6b4a3b2dc.png</url>
      <title>Forem: PhanDangKhoa96</title>
      <link>https://forem.com/phandangkhoa96</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/phandangkhoa96"/>
    <language>en</language>
    <item>
      <title>A carousel with zooming active slide using react-spring-carousel</title>
      <dc:creator>PhanDangKhoa96</dc:creator>
      <pubDate>Sun, 11 Dec 2022 05:11:13 +0000</pubDate>
      <link>https://forem.com/phandangkhoa96/a-carousel-with-zooming-active-slide-using-react-spring-carousel-4k69</link>
      <guid>https://forem.com/phandangkhoa96/a-carousel-with-zooming-active-slide-using-react-spring-carousel-4k69</guid>
      <description>&lt;p&gt;Liquid syntax error: Unknown tag 'endraw'&lt;/p&gt;
</description>
      <category>react</category>
      <category>carousel</category>
      <category>reactspring</category>
      <category>reactspringcarousel</category>
    </item>
    <item>
      <title>A blob animation can make your website more lively</title>
      <dc:creator>PhanDangKhoa96</dc:creator>
      <pubDate>Sat, 17 Sep 2022 05:38:58 +0000</pubDate>
      <link>https://forem.com/phandangkhoa96/a-blob-animation-can-make-your-website-more-lively-58p5</link>
      <guid>https://forem.com/phandangkhoa96/a-blob-animation-can-make-your-website-more-lively-58p5</guid>
      <description>&lt;p&gt;This is my first post ever :) Let's get started!!&lt;/p&gt;

&lt;p&gt;This is what the result looks like:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--HgJc9PUe--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ydo6956uk0uhoyyb338f.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--HgJc9PUe--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ydo6956uk0uhoyyb338f.gif" alt="blob animation" width="880" height="695"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In this example, i will use &lt;a href="https://vitejs.dev"&gt;Vite&lt;/a&gt; to create a new React app.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;npm create vite@latest&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;I will complete it by adding some information for my project (name and framework)&lt;/p&gt;

&lt;p&gt;Next, i am gonna create a new component called Blob.jsx and import it into App.jsx&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--YXQayEBC--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/imb2l6l1bpi00hi8yqa4.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--YXQayEBC--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/imb2l6l1bpi00hi8yqa4.png" alt="app component" width="880" height="843"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now, let's intergrate react-spring&lt;/p&gt;

&lt;h3&gt;
  
  
  React-spring
&lt;/h3&gt;

&lt;p&gt;Actually i just approached to &lt;a href="https://react-spring.dev/"&gt;react-spring&lt;/a&gt; a few weeks ago, and suprisingly i found it super powerful.&lt;/p&gt;

&lt;p&gt;React-spring gives a lot of opportunities to create wonderful animations which are super "realistic" and "physical"&lt;/p&gt;

&lt;p&gt;And the usage is also pretty easy, just install by:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;npm install react-spring&lt;/code&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Blob generator
&lt;/h3&gt;

&lt;p&gt;From now, we just setup our app, next step, we need to create two random shapes of blob (.svg format) to toggle between their paths to create the desired animation.&lt;/p&gt;

&lt;p&gt;I will use &lt;a href="https://app.haikei.app/"&gt;Haikei&lt;/a&gt; for creating them&lt;br&gt;
and download the svg format.&lt;/p&gt;

&lt;p&gt;Next, i copy these two svg blobs into my Blob.jsx component and delete &lt;code&gt;&amp;lt;rect x={0} y={0} width={900} height={600} fill="#FF0066" /&amp;gt;&lt;/code&gt; (it is just the background)&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;div&amp;gt;
                &amp;lt;svg id="visual" viewBox="0 0 900 600" width={900} height={600} xmlns="http://www.w3.org/2000/svg" xmlnsXlink="http://www.w3.org/1999/xlink" version="1.1"&amp;gt;
                    &amp;lt;g transform="translate(407.8302694033731 297.56887719695067)"&amp;gt;
                        &amp;lt;path d="M158.7 -157.7C208 -109.4 252 -54.7 244.8 -7.2C237.6 40.3 179.3 80.6 129.9 130.6C80.6 180.6 40.3 240.3 -4.1 244.4C-48.6 248.6 -97.1 197.1 -126.4 147.1C-155.8 97.1 -165.9 48.6 -159.3 6.6C-152.7 -35.4 -129.4 -70.7 -100 -119C-70.7 -167.4 -35.4 -228.7 9.7 -238.4C54.7 -248 109.4 -206 158.7 -157.7" fill="#BB004B" /&amp;gt;
                    &amp;lt;/g&amp;gt;
                &amp;lt;/svg&amp;gt;

                &amp;lt;svg id="visual" viewBox="0 0 900 600" width={900} height={600} xmlns="http://www.w3.org/2000/svg" xmlnsXlink="http://www.w3.org/1999/xlink" version="1.1"&amp;gt;
                    &amp;lt;g transform="translate(477.0920346881802 291.5807221558637)"&amp;gt;
                        &amp;lt;path d="M139.6 -142.1C164.6 -114.6 157.3 -57.3 164 6.7C170.7 70.7 191.4 141.4 166.4 167.9C141.4 194.4 70.7 176.7 3.4 173.3C-63.9 169.9 -127.8 180.8 -171.6 154.3C-215.4 127.8 -239.2 63.9 -231 8.2C-222.7 -47.4 -182.4 -94.8 -138.6 -122.3C-94.8 -149.8 -47.4 -157.4 4.9 -162.3C57.3 -167.3 114.6 -169.6 139.6 -142.1" fill="#BB004B" /&amp;gt;
                    &amp;lt;/g&amp;gt;
                &amp;lt;/svg&amp;gt;
&amp;lt;/div&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After this, i will extract the "d" attribute of each SVG path and save it as blob1 and blob2.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;   const blob1 = "M158.7 -157.7C208 -109.4 252 -54.7 244.8 -7.2C237.6 40.3 179.3 80.6 129.9 130.6C80.6 180.6 40.3 240.3 -4.1 244.4C-48.6 248.6 -97.1 197.1 -126.4 147.1C-155.8 97.1 -165.9 48.6 -159.3 6.6C-152.7 -35.4 -129.4 -70.7 -100 -119C-70.7 -167.4 -35.4 -228.7 9.7 -238.4C54.7 -248 109.4 -206 158.7 -157.7"

    const blob2 = "M139.6 -142.1C164.6 -114.6 157.3 -57.3 164 6.7C170.7 70.7 191.4 141.4 166.4 167.9C141.4 194.4 70.7 176.7 3.4 173.3C-63.9 169.9 -127.8 180.8 -171.6 154.3C-215.4 127.8 -239.2 63.9 -231 8.2C-222.7 -47.4 -182.4 -94.8 -138.6 -122.3C-94.8 -149.8 -47.4 -157.4 4.9 -162.3C57.3 -167.3 114.6 -169.6 139.6 -142.1"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Also i just keep one SVG tag and use blob1 for the path&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; &amp;lt;svg id="visual" viewBox="0 0 900 600" width={900} height={600} xmlns="http://www.w3.org/2000/svg" xmlnsXlink="http://www.w3.org/1999/xlink" version="1.1"&amp;gt;
                &amp;lt;g transform="translate(407.8302694033731 297.56887719695067)"&amp;gt;
                    &amp;lt;path d={blob1} fill="#BB004B" /&amp;gt;
                &amp;lt;/g&amp;gt;
&amp;lt;/svg&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;From now, we can add spring animation for the blob, make it transform from blob1 to blob2 shape&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    const blobAnimation = useSpring({
        from: { x: blob1 },
        to: { x: blob2 },
    })
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Don't forget to import useSpring and animated to your component. And replace the &lt;code&gt;blob1&lt;/code&gt; from "d" attribute by &lt;code&gt;blobAnimation.x&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { useSpring, animated } from 'react-spring'

...

&amp;lt;animated.path d={blobAnimation.x} fill="#BB004B" /&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, we are almost done, but the animation is too fast, we just need to add duration for it by adding &lt;code&gt;config&lt;/code&gt; option and make it loop infinitely and also reversely.&lt;/p&gt;

&lt;p&gt;Here is the useSpring code looks like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    const blobAnimation = useSpring({
        from: { x: blob1 },
        to: { x: blob2 },
        config: {
            duration: 3000
        },
        loop: { reverse: true }
    })
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And yes, we make it!&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--HgJc9PUe--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ydo6956uk0uhoyyb338f.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--HgJc9PUe--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ydo6956uk0uhoyyb338f.gif" alt="blob animation" width="880" height="695"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Hope you can find it useful and apply it to your own project! :D&lt;/p&gt;

</description>
      <category>reactspring</category>
      <category>react</category>
      <category>vite</category>
      <category>codenewbie</category>
    </item>
  </channel>
</rss>
