The SVG animation is reversing and decreasing in size from the bottom

Feeling lost, I spent a day searching without success. I have a project in full Vuejs and I thought using Svg would be easy and fun, but I can't figure out why the image resizes when playing an animation.

The bottom of the svg seems to resize and get smaller, and I am completely baffled as to why. Here is a link to the code: https://codepen.io/deeluxe/pen/VwvdgrN

<svg class="svg-wave" preserveAspectRatio="none" viewBox="0 0 1440 932">
  <path class="polymorph" d="M485.168 37.924C264.292 -30.76 69.6908 9.30565 0 37.924V932H1442V105.029C1336.46 77.3975 1129.89 162.266 1019.35 160.785C908.815 159.305 761.264 123.779 485.168 37.924Z" fill="url(#paint0_linear)"/>
  <defs>
    <linearGradient id="paint0_linear" x1="775.269" y1="112.006" x2="722.687" y2="680.065" gradientUnits="userSpaceOnUse">
      <stop stop-color="#05CDDA"/>
      <stop offset="1" stop-color="#034E53"/>
    </linearGradient>
  </defs>

But the confusion doesn't end there. When trying a simple Gauge, it plays in reverse! Check it out here: https://codepen.io/deeluxe/pen/mdeKvYe

<svg class="svg-wave" preserveAspectRatio="xMaxYMin  meet" width="240" height="561" viewBox="0 0 240 561" fill="none" xmlns="http://www.w3.org/2000/svg">
  <path class="polymorph" d="M239.5 0.5H0.5V560.5H239.5V0.5Z" fill="#EC0000"/>
</svg>
anime({
    targets: '.polymorph',
    d: [
      { value: 'M239.5 0H0.5V118.5H239.5V0Z'},
    ],
    easing: 'linear',
    duration: 8000,
    loop: true
  });

I created copies of these svgs with Figma. If anyone can help fix either of the codes, I might finally understand what's going on. Thanks!

Answer №1

If I have grasped your question correctly, the issue with the first example lies in the fact that the target path does not align perfectly with your desired outcome.

Within the d value, there is a segment stating V895, which corresponds to point 895. However, considering your viewBox has a height of 932, there remains a 37-pixel gap at the bottom.

In contrast, your original path features V932, extending all the way down to the bottom.

I am uncertain about your intentions or how you arrived at this dilemma, but substituting V895 with V932 in the target d value should prevent the blue region's lower edge from creeping upward.

I am somewhat confused by the problem described in the second example. If the issue pertains to playing in reverse, wouldn't swapping the two paths suffice?

Update:

Firstly, I recommend consulting the MDN guide on SVGs, as it provides an excellent introduction to drawing fundamental shapes:

https://developer.mozilla.org/en-US/docs/Web/SVG/Tutorial

Your most recent example exhibits some peculiar inconsistencies concerning half pixels. Utilizing half pixels by itself poses no issues, yet maintaining consistency between the starting and ending paths appears lacking.

Here is one approach to achieving your desired effect.

Initially, let's outline the initial rectangle. While you could utilize <rect> for this purpose, I will adhere to employing <path> to maintain uniformity with your previous practices.

To begin, move the cursor to the image's bottom-left corner, denoted as M0 300. Proceed by drawing a horizontal line along the bottom (H652), followed by moving up the right-hand side (V0). Subsequently, traverse along the top (H0) before concluding with a Z to connect back to the starting point. Note that when utilizing uppercase letters, coordinates are absolute rather than relative. Hence, when specifying something like V0, it signifies 'move vertically until y equals 0'. Alternatively, using lowercase letters would denote a relative position based on the current cursor location.

The finalized path appears as follows:

<path class="polymorph" d="M0 300H652V0H0Z" fill="black"/>

You may insert additional spaces for improved readability, such as M0 300 H652 V0 H0 Z.

The target path closely resembles the initial path, with the exception of adjusting the V0 component. To ensure the black rectangle does not extend entirely to the top (y=0), maintaining its final height as 44 (as per your example), we need to set

V256</code, where <code>256 = 300 - 44
due to the viewBox's height being 300.

Therefore, the revised target path reads as follows:

{ value: 'M0 300H652V256H0Z'}

To address these challenges, it is advisable to disable the animation temporarily. Initially focus on rendering the target path within your static HTML content. Once you have achieved the desired visualization, proceed with implementing animations.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Removing the blue border around a button upon being clicked

Whenever I press my button, an unexpected event occurs. Is there a solution to avoid this issue? Thank you for your help! :) ...

VueJS / v-html is displaying a blank page (Bokeh-html)

Especially as a newcomer to VueJS, I am currently in the process of trying to showcase a local HTML file within the Vue Application. The method I'm using to fetch the HTML file involves Axios, here's how it goes: <template> <div> ...

Browser does not support the Media Query

I'm completely puzzled by Media Queries. I've been attempting to resolve this issue but cannot seem to identify where the problem lies. While creating a website with Wordpress, my header.php contains the following line: <meta name="viewpo ...

Issue with CSS not loading correctly when switching routes in AngularJS using Gulp and Router

I currently have a router set up in my application: var mainmodule.config(function($routeProvider){ $routeProvider.when('/home',{ templateUrl:'src/home/home.html' }; $routeProvider.when('/home/sports',{ ...

Discover the possibilities of setting the dimensions of your anchor tags using only inline-block spans

Can anyone help me understand what is happening with this small piece of HTML code? http://jsbin.com/akome5 When viewed on various browsers such as FF4, Chrome10, IE9, IE8, Opera 11, the layout of the element appears like this: Hmm, why is this happenin ...

Tips on integrating data from Vuex into your component

How can I effectively utilize the data fetched using the Vuex store's action in a specific component? import axios from 'axios' export default { namespaced: true, state: { items: [] }, actions: { fetchCategories ({state, c ...

Application with menu design, similar to the layout of google.com on mobile devices

Have you seen the Android smartphone with Chrome from GOOGLE.COM? Did you notice the pop-up MENU that looks similar to an application? This menu has a "SPRING" effect, and I'm curious how Google achieved this result. I tried using the property "-web ...

Selected Angular Radio Button

Back in the good ole days of basic HTML and CSS, I was able to achieve the following: input:checked+label { background-color: #f00; } <div class="col-xs-6"> <input type="radio" id="template-1" name="template" value="template1" checked> ...

Two CSS borders of varying heights

Just wondering, can we achieve something similar to the style shown in the attachment using only CSS? <h3 style="border-bottom:1px solid #515151"><span style="border-bottom:3px solid #0066b3">HEADER</span></h3> ...

The grid layout in Bootstrap 4 does not seem to be compatible with dompdf

I am in the process of using dompdf for rendering a PDF file. Our application is built on Bootstrap 4 framework, and I want to incorporate it into the twig template used for generating our documents. However, I have encountered an issue with the Bootstrap ...

Refresh the content of VueJS Resource

Resource file helper/json_new.json { "content": { "content_body": "<a href='#' v-on:click.prevent='getLink'>{{ button }}</a>", "content_nav": "", } } Vue script.js file new Vue({ el: 'body', ...

What could be the reason for my onChange event not functioning properly?

The issue I'm experiencing involves my onchange event not properly copying the text from the current span to the hidden field. Any ideas on why this might be happening? Check out my code at this link. ...

Issue with background/hero video not adjusting its size

I've been experimenting with creating a page that features a video as the background, but no matter what I try, the video never seems to resize properly. The image below shows how it looks: image in question body { margin: 0; } .hero-se ...

Difficulty arises with z-index when hover effects are applied to clip-path shapes

I'm encountering an issue where I am attempting to make two clip path polygons overlap each other when hovered over by the mouse. I have been using z-index values and trying to adjust them based on which overlay is being hovered over, but unfortunatel ...

What sets apart the intended usage of the DOM `hidden` from the CSS `visibility` property?

Exploring the DOM property hidden and the CSS property visibility, I find myself unsure of when to utilize each one. What are the distinctions in their intended purposes? While they may serve similar functions, I am curious about the underlying motivation ...

Is there a way to temporarily toggle classes with jQuery?

Incorporating ZeroClipboard, I have implemented the following code to alter the text and class of my 'copy to clipboard button' by modifying the innerHTML. Upon clicking, this triggers a smooth class transition animation. client.on( "complete", ...

What is the most efficient method for identifying and modifying an element's in-line style while performing a swipe gesture?

Recently, I've been developing a left swipe gesture handler for chat bubbles. Implementing touchMove and touchStart seems like the logical next step, but for now, I'm focusing on making it work seamlessly for PC/web users. I managed to make it f ...

What could be causing jQuery animate to malfunction on mobile devices when a viewport is present?

Everything seems to be working fine on my desktop webpage, but when I try it on mobile, there is no scroll... $("HTML, BODY").animate({ scrollTop: 500 }, 1000); This post suggests that mobile devices may not scroll on the body, but on the vi ...

State in Vuex is failing to update effectively when actions are being utilized

I'm trying to wrap my head around VueX, but I'm having trouble getting Axios to work with it. In my store.js file, I have the following setup: state: { cards: [], currentPage: 1, lastPage: 2, }, actions: { loadGradients(page ...

Is there a way to verify if a mixin has been successfully applied to the component?

I am currently conducting tests on a VueJS 2 application using the vue-test-utils library. I am striving to verify whether the specific component has received the mixin. This involves mounting the component utilizing the mount function and then attempting ...