javascriptsvganime.jssvg-morphing

SVG morph not morphing smoothly - anime js


I am trying to create a simple SVG morph using Anime JS but the SVG doesn't transition smoothly as you can see below it jumps. Does anyone know why this is happening?

const SVG_PATHS = [
	{ value: "M1920,349H0V242s468-52.44,960-73.33S1920,0,1920,0Z" },
   { value: "M1920,466H0V359s159-60,960-73S1920,0,1920,0Z" }
];

const MORPH_SVG = anime({
   targets: ".path",
   d: [
      SVG_PATHS[1], 
      SVG_PATHS[0]
      ],
   easing: "linear",
   duration: 5000,
   loop: true
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/animejs/2.0.2/anime.min.js"></script>
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1920 349" class="svg_curve">
	<path style="fill: #000;" d="M1920, 349H0V242s468-52.44, 1160-73.33S1920, 0, 1920, 0Z" class="path"/>
</svg>


Solution

  • Use SVG_PATHS[0] as value for the path

    const SVG_PATHS = [
    	{ value: "M1920,349H0V242s468-52.44,960-73.33S1920,0,1920,0Z" },
       { value: "M1920,466H0V359s159-60,960-73S1920,0,1920,0Z" }
    ];
    
    const MORPH_SVG = anime({
       targets: ".path",
       d: [
          SVG_PATHS[1], 
          SVG_PATHS[0]
          ],
       easing: "linear",
       duration: 5000,
       loop: true
    });
    <script src="https://cdnjs.cloudflare.com/ajax/libs/animejs/2.0.2/anime.min.js"></script>
    <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1920 349" class="svg_curve">
    	<path style="fill: #000;" d="M1920,349H0V242s468-52.44,960-73.33S1920,0,1920,0Z" class="path"/>
    </svg>