Adjust SVG color transition height based on CSS class characteristics

Utilizing a combination of SVG and CSS code, I am attempting to animate the fill level of an SVG shape.

.st0 {
  fill: none;
  stroke: #000000;
  stroke-width: 4;
  stroke-miterlimit: 5;
}

.st1 {
  fill: none;
  stroke: #000000;
  stroke-width: 3;
  stroke-miterlimit: 5;
}

#logo2 {
  width: 150px !important;
  height: 150px !important;
  position: relative;
  margin-top: -100px;
}

#banner {
  border-radius: 50%;
  width: 150px;
  height: 150px;
  background: #fff;
  overflow: hidden;
  backface-visibility: hidden;
  transform: translate3d(0, 0, 0);
  z-index: -1;
  margin-bottom: -50px;
}

#banner .fill {
  animation-name: fillAction;
  animation-iteration-count: 1;
  animation-timing-function: cubic-bezier(.2, .6, .8, .4);
  animation-duration: 4s;
  animation-fill-mode: forwards;
}

#banner #waveShape {
  animation-name: waveAction;
  animation-iteration-count: infinite;
  animation-timing-function: linear;
  animation-duration: 0.5s;
  width: 300px;
  height: 150px;
  fill: #04ACFF;
}

@keyframes fillAction {
  0% {
    transform: translate(0, 150px);
  }
  100% {
    transform: translate(0, -5px);
  }
}

@keyframes waveAction {
  0% {
    transform: translate(-150px, 0);
  }
  100% {
    transform: translate(0, 0);
  }
}
<div>
  <div id="banner">
    <div>
      <svg version="1.1" id="logo" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" xml:space="preserve">

          <defs>
<clipPath id="drop">
                <path transform="scale(0.75), translate(32,0)"
                  d="M68.2,6.7c0,0-62.4,70.9-62.4,124.7c0,32.3,28,58.4,62.4,58.4s62.4-26.2,62.4-58.4
                    C130.7,77.6,68.3,6.7,68.2,6.7z M61,77.5c0.8,0,1.5,0.7,1.5,1.5v20.6c2.7-3.6,7.6-5.7,13.1-5.2,0,19.4,6.9,19.4,18.7v37.2
                    c0,0.8-0.7,1.5-1.5,1.5H75.6c-0.8,0-1.5-0.7-1.4-1.5v-32c0-4.1-1.8-6.4-5-6.4c-5.8,0-6.7,5.7-6.7,5.7v32.7c0,0.8-0.7,1.5-1.5,1.5
                    H43.1c-0.8,0-1.5-0.7-1.5-1.5V79c0-0.8,0.7-1.5,1.5-1.5H61z" />
              </clipPath>
          </defs>

          <g clip-path="url(#drop)">
        <g class="fill">
          <path fill="#04ACFF" id="waveShape" d="M300,300V2.5c0,0-0.6-0.1-1.1-0.1c0,0-25.5-2.3-40.5-2.4c-15,0-40.6,2.4-40.6,2.4
c-12.3,1.1-30.3,1.8-31.9,1.9c-2-0.1-19.7-0.8-32-1.9c0,0-25.8-2.3-40.8-2.4c-15,0-40.8,2.4-40.8,2.4c-12.3,1.1-30.4,1.8-32,1.9
c-2-0.1-20-0.8-32.2-1.9c0,0-3.1-0.3-8.1-0.7V300H300z" />
        </g>
      </g>
      <g transform="scale(0.75), translate(32,0)">
        <path class="st0" d="M68.2,6.7c0,0-62.4,70.9-62.4,124.7c0,32.3,28,58.4,62.4,58.4s62.4-26.2,62.4-58.4
C130.7,77.6,68.3,6.7,68.2,6.7z" />

      </g>
        </svg>
    </div>
  </div>
</div>

I have been unable to adjust the height of the "water level" animation as desired. My goal is to be able to change the height of the animation using a CSS class to achieve different fill levels such as 75% or 25%. However, my attempts to alter the height via CSS have not been successful and are being overlooked.

Answer №1

Adjusting the animation being played can alter the level at which it ascends.

You have the option to choose which animation to play by adding an additional class.

I decided to halt the wave animation as it was making me feel seasick.

Main points to note:

To change the animation style, you must use an extra class in conjunction with the fill class. This allows you to specify which animation to apply for each class.

.fill.fill-25 {
    animation-name: fillAction25;
}
.fill.fill-50 {
    animation-name: fillAction50;
}
.fill.fill-75 {
    animation-name: fillAction75;
}

Afterwards, I adjusted the translation height of the animations in the keyframes section. You can even utilize the calc method like this calc(155px / 100 * 25) to compute custom percentages.

@keyframes fillAction25 {
  0% {
    transform: translate(0, 150px);
  }
  100% {
    transform: translate(0, 115px);
  }
}
@keyframes fillAction50 {
  0% {
    transform: translate(0, 150px);
  }
  100% {
    transform: translate(0, 85px);
  }
}
@keyframes fillAction75 {
  0% {
    transform: translate(0, 150px);
  }
  100% {
    transform: translate(0, 45px);
  }
}

Furthermore, you may integrate the calc method within the animations for customized percentage calculations.

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

The pseudo-class for invalid input triggers CSS invalidation, even when the input field is left blank

The input property for handling invalid input is currently malfunctioning. It triggers an error even when the input field is left empty. I would like the input border to be goldenrod when it's empty, turn red if the input doesn't match the specif ...

Encountering difficulties with the mobile display of a Wordpress theme

I am currently working with the megashop theme on WordPress and I have a few queries that need addressing: Is there a way to modify a specific setting exclusively for views smaller than desktop size, without impacting the desktop view? For example, the m ...

Navigating to a Fresh Angular App Post Successful Login and Subscription

Hello everyone, I am currently working on a personal Angular project that involves two separate Angular applications. The first is the main application, and the second application is meant to be redirected to after login and subscription validation. Howev ...

Could anyone provide a breakdown of the code listed below?

Help me unravel the mysteries of Promises! I have a challenge ahead of me. I need to write a function that will display 3000 after 3 seconds, then display 2000 after 2 seconds, and finally 1000 after 1 second. This is what I have so far: 'use strict& ...

How selection.join behaves when every node contains child elements

I have been following the amazing tutorial on to learn more about the join paradigm. Everything was working fine until I tried to make each node more complex by adding a group with text inside. The main group gets updated, but the child one does not. Sn ...

Multi-line D3 chart that dynamically updates and intersects with the axis

I am attempting to create a multiline d3 chart that can be updated with new datasets. I have developed a method to plot the new data on the existing d3 frame, but I am encountering issues when trying to update the chart with mocked data. The new data is no ...

Creating a responsive layout in HTML/CSS where the div element expands to fill the entire vertical space of its parent

Looking for assistance in creating a webpage layout like the one shown in this fiddle... http://jsfiddle.net/jeljeljel/5BSva/ I need the vertical line on the left side navigation tab to extend all the way down to the footer at the bottom of the page. Th ...

Having trouble passing data from router to View with EJS in Express. Despite trying, still encountering ReferenceError message

I encountered an issue when trying to display form errors to the user. I attempted to pass the errors from the router to my view file. Error Message ReferenceError: e:\2016\passport\views\register.ejs:38 36| 37| <div ...

What is the best way to add clickable links to 3D objects and meshes with ThREE?

My goal is to create a simple box that can act as a link when clicked. This seemingly straightforward task has proven difficult for me, so I would greatly appreciate any assistance. Despite my efforts to troubleshoot and research online, I have not been ...

What is the best way to retrieve a value from a promise in JavaScript?

As someone who is relatively new to working with promises, I find myself in a bit of a sticky situation. Despite reading several articles and Stack Overflow posts on the topic, I still can't seem to fully grasp it. My dilemma involves a simple API th ...

Guide for sending token through Authorization in Laravel 8 API

I am currently utilizing Laravel 8 as an API REST and encountering an issue where my token is null when sent in the AJAX request. I have successfully handled logins and requests without tokens, but this specific scenario has me puzzled. Within my JavaScri ...

Retrieve the URL by ID from the article when expanding the accordion

I am trying to include the article ID in the URL when the a href link is clicked in the code below. I've updated the code to include the PHP section and added a while loop with the article ID. require_once("inc/connection.php"); mysql_select_db("nie ...

Issue with JSON data not functioning properly in AJAX request

I have been facing an issue with detecting whether a database entry has been successfully input. I am sending the new inserted ID and a JSON variable to an AJAX call, which works fine in all browsers but not in phonegAP. Despite that, the data is being suc ...

"Implementing a feature in React JS react-table to dynamically add a new column when a

I'm struggling to add a new column to react-table when a button is clicked. Even after re-rendering the table with a flag, I can't seem to add the new column. Can anyone suggest where I might be going wrong? Here's the link to the executable ...

Tips for preventing Razor from interpreting special characters as HTML code

I'm encountering an issue with special characters displaying as HTML codes on the page I'm working on. The content is retrieved from a database and shown in readonly input boxes. For example, & is displayed as &. How can I ensure that the ...

Remove an item from a list using Vue.js and Javascript

I have a votes array containing user information. I am looking to delete a user based on their id. role: 2 active: 2 about: null id: 3 email: "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="126677616652757f737b7e3c717d7f3c717 ...

Ways to soften a section of a canvas component?

What is the simplest way to apply a blur effect to a specific portion of my canvas element? I am utilizing the JavaScript 3D Library known as three.js. This library simplifies the use of WebGL. While they offer examples of blur and depth of field effects, ...

Tips for adjusting the size of nav-pills when collapsing with bootstrap 5

I'm attempting to utilize Bootstrap to create active classes that display a nav-pill/container around the active section of my webpage. It works well on larger screens, but on smaller screens with the hamburger menu active, the nav-pill stretches acro ...

How can I dynamically update HTML content in React upon receiving an AJAX response?

Hi there, I'm new to using React and I have a requirement where I need to make an AJAX GET request to the server when a user clicks on a button. Based on the received response, I need to prepare HTML and display it. I tried implementing this with the ...

The drop-down menu keeps flickering instead of remaining open when clicked

I am facing an issue with a dropdown menu in my webpage. The menu is initially hidden, but should become visible when the list element containing it is clicked. I have written JavaScript code to add a class that changes the visibility property to visible u ...