Can an animation be created that transforms an SVG line into a flawless circle?

Is there a way to create an animation that starts with an SVG line and gradually widens from the center to form a perfect circle?

I've been researching this, but haven't found a solution that meets my needs. It could be because of the keywords I'm using or some other reason.

Here is the code for my line:

<svg height="210" width="500">
  <line x1="150" y1="150" x2="50" y2="150" style="stroke:rgb(255,0,0); stroke-width:2" />
</svg>

… and the animation I'm trying to achieve should look like this:

Answer №1

If you want to achieve this effect using only CSS, here's how you can do it:

.container {
  width:250px;
  height:4px;
  background:radial-gradient(circle,#000 99px,transparent 100px);
    
  animation:transformHeight 5s linear 1s forwards;
}
@keyframes transformHeight {
  to {
    height:200px;
  }
}

body {
  margin:0;
  height:100vh;
  display:flex;
  align-items:center;
  justify-content:center;
}
<div class="container">

</div>

Answer №2

There is a creative way to transition an SVG ellipse from a straight line to a perfect circle:

svg {
  background-color: #fff;
}

ellipse {
  background:radial-gradient(circle,#000 99px,transparent 100px);
  animation:toCircle 1s linear 1s forwards;
}

@keyframes toCircle{
  to {
    ry:50;
  }
}
<svg width="700" height="500">
<ellipse cx="100" cy="100" rx="50" ry="0.1"/>
</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

Error: html2canvas encountered an uncaught undefined promise

Currently, I am working with an HTML canvas tag: <canvas id="myCanvas"></canvas> I have successfully created a drawing on this canvas, and it looks exactly how I wanted it to. However, when trying to convert it to a PNG file using html2canvas ...

Efficiently running multiple PHP pages with just one simple click

Below is the code fragment that I currently have: <html> <script type="text/javascript"> function Run() {var a=["ONE" ,"TWO" ,"THREE", "FOUR", "FIVE"]; window.location.href = "index.php?w1=" +a;} </script> <body> <input type="b ...

Having trouble applying overlays to list items with CSS

I'm currently working on a grid gallery where I've set the List items to be 20% wide so there can be 5 in one row using float:left. Now, I'm trying to add an overlay effect by using a div with the class "overlay" so that when someone hovers ...

Utilizing CSS3 to perform multiple 3D rotations

I am attempting to rotate a face of a cube twice in order to have that face fall flat on one side. For reference, please see the illustration of my goal here: https://i.stack.imgur.com/kwO8Z.png I have included my current progress below, using a 45-deg ...

Numerous SVGs sharing identical IDs

Is it possible to include multiple SVGs on an HTML page and utilize the same IDs in each of them? <div> <svg height="0" width="0"> <clipPath id="svgPath"> ........ </svg> <svg height="0" width="0"> < ...

The issue of the Dropdown Menu Not Remaining Fixed While Scrolling

There is a challenge with a Datetime Picker Dropdown Menu not staying in place when the user scrolls. Previous attempts to use .daterangepicker {position: fixed !important;} have been unsuccessful, causing the Datetime Picker to not stay fixed in its posit ...

html td elements are breaking due to the application of ngFor

<table> <tr> <th>Date</th> <th>Products</th> </tr> <tr *ngFor="let x of orderdetails"> <td>{{x.orderdate}}</td> <td *ngFor="let y of x.orderproducts"> <span class="break">{{y}}</s ...

Position an iframe in alignment

I'm working on a HTML page and I have been trying to figure out how to align an iframe at the bottom of the page so that it spans the entire width. Despite my efforts, I haven't been successful in getting the iframe to align properly at the botto ...

Generating values in a loop - mastering the art of creating data points

My goal is to create a variable within a loop: box-shadow: 835px 1456px #FFF, 1272px 796px #FFF, 574px 1357px #FFFand so on... The concept is simple: box-shadow: x1 y1 #fff, x2 y2 #fff, x3 y3 #fff, x4 y4 #fff ... xn yn #fff. I attempted to achieve this ...

Adjust the height of the Twitter Widget to be proportionate to the height of its parent div dynamically

I have integrated the Twitter widget into my library management system, but I am facing an issue with its fixed height. Is there a way to make the height dynamic through CSS? Any suggestions on how this can be achieved will be greatly appreciated. Below ...

There are three checkboxes, one of which is independent of the others and requires jQuery to not consider it part of the collection

Initially, I crafted a query that perfectly met the business requirement until there was a change of heart. Uncheck checkbox if checked with jquery The implementation of this code was flawless $('input[type="checkbox"]').on('change' ...

Applying CSS blur filter to container without affecting its content

I'm trying to create a hover effect where an image within a parent div transitions into a blurred state. However, I've run into an issue where if the image is set to 100% width/height of the parent div, there is a visible bezel of the parent&apos ...

How to use jQuery to dynamically set the value of a column span in a

Struggling with setting the value for a table column span. Here is my jQuery code: $('tr td data-th=Name span').val('My span content...'); This is how my HTML appears: <tr> <td data-th="Name"><span class="edit-inpu ...

Leveraging Firebase for data storage in creating XML files

According to my understanding of the firebase documentation, data that is inputted is converted into JSON format. The easiest way to connect to firebase is through the use of javascript. However, is it feasible to utilize the JSON data in firebase to gen ...

Tips for arranging two svg elements next to each other within a larger div

Hey everyone, I've been working on some HTML and JavaScript but I'm stuck on a basic issue. I have a simple code with a div containing two inner divs, each with an SVG element equal to the size of the parent div. My goal is to have these two inne ...

Tips for navigating through elements generated with ng-repeat as I scroll

There is a list generated using ng-repeat along with two buttons for moving up or down. Users have the option to select any item from the list and utilize the buttons to navigate through it. However, when I lower the selected item using the "go down" butt ...

Is it possible to create a Bootstrap4 fullscreen dashboard featuring dynamically resizing images that perfectly fit and stretch within their respective divs

I have been attempting to make this work for a few days now, but with no success. This is specifically designed for a larger monitor (2560x1080), so responsiveness on smaller viewports is not a priority. My goal is as follows: Fit the container to the f ...

Access a designated tab within a CSS-designed tab system

Can anyone offer some assistance? I currently have a tab structure created using CSS. The first tab is set as the default when the page loads. I am looking to create a link from another page that will take users directly to the page with the tabs and ope ...

Is the original image source revealed when clicked?

I've implemented an expand and collapse feature using jQuery/JavaScript. Clicking on the DIV causes the image inside to change state. However, clicking on the same DIV again doesn't return the image to its original state; it remains stuck in the ...

Assign an onClick event to a Button that was dynamically generated within a loop in JavaScript

Is there a way to set the onClick property for buttons created within a loop? I've tried using JQuery with no success. for(started somewhere... var button = document.createElement('button') var div = document.createEl ...