Is it possible to create dynamic animations with SVG files?

I am currently in the process of coding my website, and I came up with an exciting idea to animate my navigation bar within an SVG container. With its naturally wavy design, I aim to achieve a sweeping wave effect similar to the intro animation on Discord. I'm exploring different options to bring this concept to life, so any suggestions involving JQuery, Java, CSS, or any other tools are welcome.

While I have some experience working with CSS, I feel a bit lost when it comes to implementing Java or JQuery for this particular task. Ideally, I would like the animation to trigger onClick events, possibly tied to a Hamburger Menu.

body {
  font-family: 'Raleway', Arial, Verdana, sans-serif;
  overflow-x: hidden;
}

a {
  text-decoration: none;
  color: white;
}

.main_hd_cont {
  position: absolute;
  top: -1.25vw;
  left: 1.5vw;
  z-index: 2;
  color: white;
}

.main_hd_txt {
  font-size: 3.5vw;
  font-family: 'ballet_harmonyballet_harmony';
}

svg {
  filter: drop-shadow(.5vw .5vw .15vw rgb(0, 0, 0, 0.6));
}

.navigation_svg {
  position: absolute;
  top: 0;
  left: 0;
  z-index: 1;
  max-width: 100vw;
  width: 100vw;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<!DOCTYPE html>
<html>

<head>
  <title>Code Cafe | Home </title>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <link rel="stylesheet" type="text/css" href="../CSS/stylesheet.css">
  <!--Fonts from Google Fonts API Directory, all rights reserved to original typographers and the Google Corperation -->
  <link href="https://fonts.googleapis.com/css?family=Raleway" rel="stylesheet">
  <!--Styling for Font Awesome Icon library, for high quality icons visit Font...;
The current state is limited to a fading effect, which was merely an experimental use of @keyframes to animate SVGs.

Answer №1

One way to animate the path's d property using CSS is as follows:

path {
  transition: d 1s;
  d: path('M547 93.0001C496 38.0001 457 29 372 15C276.086 -0.79759 -57 -52 9.99988 240C33.2036 341.127 87.9999 397 157 366C226 335 285 227 325 341C365 455 407 425 598 412C789 399 841 322 839 233C837 144 688 162 642 169C596 176 598 148 547 93.0001Z'); 
}

path:hover {
  d: path('M547 92C471.994 92 482.5 -39.5 372 14C284.509 56.3601 -57 -53 9.99984 239C33.2035 340.127 82.5699 351.503 157 365C253.5 382.5 248.741 246.296 325 340C401.5 434 445.063 526.153 598 411C768 283 874.5 310 839 232C802.123 150.975 671.067 131.667 642 168C616 200.5 613 92 547 92Z'); 
}
<svg viewBox="0 0 900 500">
  <path d=""/>
</svg>

Animating with keyframes

path {
  animation: 10s infinite alternate wave ease-in-out;
}

@keyframes wave {
  from {
    d: path("M2,5 S2,-2 4,5 S7,8 8,4")
  }
  to {
    d: path("M2,5 S2,14 4,5 S7,8 8,4")
  }
}



body {display: flex;}
svg {width: 100%;}
path {fill: none;stroke: #000;}
<svg viewBox="0 0 10 10">
  <path d="M2,5 S2,-2 4,5 S7,8 8,4" />
</svg>

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

What is the best approach to preserving and retrieving a Three.js scene?

I've come across loaders for individual objects and elements, but is there a way to save and load entire scenes in three.js? ...

The automated linting process through npm script did not meet the desired expectations

I need help setting up a script that will automatically fix all files in my Vue project like this: "lint": "eslint --fix vue/**/*.vue && eslint --fix vue/**/*.js" The goal is to automatically lint all .vue and .js files within the project. Unfor ...

What are the steps for implementing timezone-js?

I found a project on GitHub that claims to convert one timezone to another. I've been trying to get it to work without success. After downloading and extracting the files, I created an HTML file with the following code: <html xmlns="http://www.w3. ...

Background image investigation

As a newcomer to web development, I am facing challenges in achieving the desired look for my first website. Despite spending over 2 hours researching and testing various CSS properties, I have not made much progress. What I aim for is quite straightforwa ...

HTML elements have a delayed rendering process in ReactJS

As I dive into learning ReactJS by creating a ReactJS version of my blog, I encountered an interesting issue while testing Google Page Speed. The recommendation to "prioritize visible content" led me to add a placeholder article with a loading message, lor ...

Sort the array by the elements in a separate array

Here is a filters array with three values: serviceCode1, serviceCode2, and serviceCode3. ['serviceCode1', 'serviceCode2', 'serviceCode3'] I have another array with approximately 78 records that I want to filter based on the a ...

Getting the value of radio button groups in C# - A complete guide

Here is the HTML code: <form runat="server"> <table> <tr> <td> From Date: </td> <td> <input type="text" runat="ser ...

I'm still searching for a proper solution on how to access JavaScript/jQuery functions within Colorbox

For my website, I am utilizing PHP, jQuery/JavaScript, Colorbox (a jQuery lightbox plugin), Smarty, and other tools. Currently, I am working on displaying data in a popup using the Colorbox plugin. However, I am facing an issue with calling a JavaScript fu ...

When using HLS with Media Source Extensions on mobile devices, the <video> element with the muted and autoplay attributes may freeze on the first frame

I recently added a background video to our website using mux.com. The video is set to autoplay with HLS, but Chrome requires Media Source Extensions for playback. To ensure the HTML5 video auto plays, I included the necessary mute parameters as well. How ...

What is the reason for not using ng-attr-width to set the width of this SVG?

I am facing a challenge in understanding ng binding on a simple web page I created to experiment with: <html ng-app="AngularSVGTestApp"> <head> <title>Angular SVG Test</title> <style> svg { backgro ...

Take the attention away from the canvas

Is there a way to shift focus away from the canvas and onto input fields in my HTML code? Right now, the canvas is holding onto focus even when I'm clicking on text inputs. This prevents me from typing anything into them. Ideally, I'd like for t ...

Creating HTML content from a function return in Angular

I'm trying to figure out the process through which TypeScript and HTML exchange data. (TypeScript) public getContactByTradingPartnerId(tradingPartnerId: number):string { const map = { 1001 : "<a href="/cdn-cgi/l/email-protection ...

While attempting to deploy on Vercel, I encountered an error while constructing my Next.js project

While working on my Next login signup project, I encountered the following error: WagmiProviderNotFoundError: `useConfig` must be used within `WagmiProvider`. The documentation for this issue can be found <a href="https://wagmi.sh/react/api/WagmiProvide ...

Sending JSON data parsed by oboe.js to the http response object in a Node.js server

Using Oboe.js for JSON parsing from a Node readStream with the aim of sending it back to the requesting client in a memory-efficient manner. I'm exploring the possibility of piping data from Oboe's node or path events to a Node.js HTTP response o ...

What impact does the use of CSS in emails have on various email clients and reading formats?

As I delve into customizing my very first (woocommerce) email template, I am considering the option of concealing data using CSS display: none. However, a few questions arise regarding the compatibility and support of CSS and display: none: Do all email ...

Issue with NgModule in Angular application build

I'm facing an issue with my Angular application where the compiler is throwing errors during the build process. Here's a snippet of the error messages I'm encountering: ERROR in src/app/list-items/list-items.component.ts:9:14 - error NG6002 ...

Incorporating a scroll feature using Ionic React

Currently, I am attempting to include a button in my Ionic React project that will smoothly scroll to the top of the page. Below is a snippet of the code I have written thus far: ... function scrollToTop() { return document.getElementById("page")!.scr ...

Difficulty encountered when utilizing $_POST with a text area

Having a contact form on a website with 2 text fields, 1 textarea, and 1 hidden field is resulting in an unexpected issue. Despite all the fields posting to a PHP script, the textarea data is not being captured as expected. This is puzzling considering the ...

Solution to trigger CSS :hover to refresh following a transition (such as expanding a menu)

While there are existing discussions on this topic, I am presenting my query for two specific reasons: It introduces a potential alternative solution The demo code could be helpful to individuals looking to emulate a menu Following a CSS transition, the ...

What is the best way to reference a PHP file located outside the same directory as the main PHP file?

My current file structure looks like this: Wamp>www>Newlinks CSS (folder) header.php footer.php Profiles (folder) MainPHPfile.php I'm trying to include the header and footer files into MainPHPfile.php, but it's not working ...