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

Illustrating SVG links

I'm working on a basic svg animation project where I want to create a simple shape by animating a line under a menu link. The goal is to have a single line consisting of a total of 7 anchors, with the middle 3 anchors (each offset by 2) moving a few p ...

Having trouble with implementing checkbox hack syntax

I'm trying to achieve a unique effect where a label gets styled and a div gets revealed when a checkbox is checked. Surprisingly, I've managed to make one happen without the other in my attempts. Even though the CSS is consistent in both instance ...

Having trouble getting the full width of a hidden div to work properly?

I am facing an issue with a two-part menu design: the left side consists of a traditional UL, while the right side contains a link within a div element. The fixed-width of the right div is causing complications as the left div needs to occupy all remaining ...

Why is it that a click event outside of an HTML element cannot be detected in this Vue 3 application?

I've been diving into building a Single Page Application using Vue 3, TypeScript, and The Movie Database (TMDB). Currently, I'm focused on developing a search form within my project. Within the file src\components\TopBar.vue, here&apo ...

The challenge of removing an event listener

There are three Div elements with a box appearance. When the user clicks on any div, a copy of that div will be added to the end. The original clicked div will no longer be clickable, but the new div will be. This process can repeat indefinitely. I attemp ...

Building chat rooms using VueJS

For my project, I am developing a Queue System using Node (SocketIO), VueJS, and MySQL. The goal is to automatically create a new chat room once 5 people have joined the queue. I already have the main chat component created, but now I need to figure out ...

What could be causing the lack of functionality in my nested CSS transition?

My markup includes two classes, fade-item and fade. The fade class is nested within the fade-item class as shown below: <a class="product-item fade-item" (mousemove)="hoverOn(i)" (mouseleave)="hoverOff(i) > <div class= ...

The `sameAs` validator in vuelidate does not function properly when using the `not` validator with a computed value

I am facing an issue with getting the not validator to work in conjunction with a computed sameAs value. While I am using the term "computed" here, I am not completely certain if it is the most accurate term. Hopefully, alongside the reproducible code pr ...

"While attempting to delete an object with axios and Symfony, a status code 500 was returned. However, the

I've been working with Vue.js for my frontend. Currently, I'm facing an issue where I want to delete an object from the database upon pressing a button. The problem arises when I try to send a post request using axios and I receive the following ...

The menu on the webpage in smartphone mode is infiltrating other divs on the page

Encountering an issue with the TwitterBootstrap CSS menu on this page when viewed on a smartphone: The div containing the menu does not resize its height, causing it to invade the content below when the "Menu" is clicked. I've been unable to find a ...

Tips for updating the current user's username value in local storage in Angular

https://i.stack.imgur.com/ZA32X.png https://i.stack.imgur.com/iDHZW.png I am facing an issue with updating the local storage of a current User for only username. When I update the username, it's not reflecting in local storage. Even though I can s ...

Why is the last move of the previous player not displayed in this game of tic tac toe?

Why does the last move of the previous player not show up in this tic-tac-toe game? When it's the final turn, the square remains empty with neither an "O" nor an "X". What could be causing this issue? Here is the code snippet: The HTML code: <div ...

Issues arise with the Dropend Menu in Bootstrap when attempting to utilize a dropdown menu

As I work on developing a sidebar using Bootstrap 5, I encountered an issue with the positioning of a "Dropdown" and "Dropend" menu when they are open. Specifically, while the Dropdown menu functions correctly, the Dropend menu does not align properly. In ...

Scrolling in Bootstrap 4 Cards conceals the fixed Header

Here's some HTML code featuring Bootstrap 4 elements. It showcases a fixed Header and Footer with scrollable Bootstrap Cards in between. When scrolling, the Headers may be hidden by the Cards. How can you adjust the layout so that the Cards scroll "be ...

What could be causing the undefined status of this length function?

I need to determine the length of seconds. If the second is only one character long, I want to add a 0 in front of it. Otherwise, no action is needed. Below is my code: <p>Click the button to show the current number of seconds.</p> <p id= ...

What is the best way to load the contents of an HTML file into a <div> element without it behaving as an object?

Currently, I am importing an HTML file into a <div> in this manner: function load_content() { document.getElementById('content').innerHTML = '<object type="text/html" width="100%" height="100%" data="./content.html"></obj ...

What causes the error message "Request payer account number does not match session" to appear when utilizing the PayPal smart button with multiple recipients?

Can I use login information or smart buttons to pay multiple payees? I attempted the following: paypal.Buttons({ createOrder: function(data, actions) { return actions.order.create({ purchase_units: [{ reference ...

What could be causing my jQuery animation to lack smoothness?

I am experiencing an issue where, after a delay, my element completely jumps across the screen to its new position when I animate its height. Strangely, this problem only occurs when using pixel values and not percentages. Unfortunately, I need to use pi ...

What is the best way to manage horizontal scrolling using buttons?

I was hoping that when the button is clicked, the scroll would move in the direction of the click while holding down the button. Initially, it worked flawlessly, but suddenly it stopped functioning. export default function initCarousel() { const carous ...

Is it possible to arrange elements in CSS based on their attribute values?

I need to arrange a list of images in ascending order based on the index attribute using CSS. The challenge is that the index values will change dynamically and new images will be added through Ajax, so I want them to automatically update in the correct or ...