Setting the initial position for an SVG path

Working on a unique loading animation with 3 shapes that will scale as they follow a path. Each shape begins from a different starting point but follows a similar path. Shapes and paths were created in Illustrator and exported as SVGs. See below for an example of the largest shape and its path.

https://i.sstatic.net/T14ix.png

My challenge is finding an efficient method to set the starting point without resorting to trial and error with path points. The current starting point, shown in this image, is not ideal.

https://i.sstatic.net/uaVWi.png

.loading-wrap {
    width:200px;
    height:200px;
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%,-50%);
}
.cir-3 {
    width:50px;
    height:50px;
    border-radius: 50%;
    background:cornflowerblue;
    position: absolute;
    top: 30%;
    left: 30%;

    offset-path: path("M147.33,108.45A49.76,49.76,0,0,0,97.57,58.69c-22.33,0-45.32,20.86-47.52,35-1.46,4.68-2.23,19.13,61,21.5-.79,14.37-43.76,9.63-61.5,6.39a49.77,49.77,0,0,0,97.78-13.09Z");
    
    animation: move 3s ease-in-out infinite reverse;
}

@keyframes move {
    100% { 
        offset-distance: 100%;
    }
}
    <div class="loading-wrap">
            <div class="cir-1"></div>
            <div class="cir-2"></div>
            <div class="cir-3"></div>
        </div>

EDIT: Check out the codepen for a live demo: https://codepen.io/CodeFreeze/pen/JjGNLRN

Answer №1

I have come up with a unique solution that involves incorporating 3 different animations for each div element. Each div is assigned a distinct initial offset-distance, and the animation transitions it to a different value.

.loading-wrap {
  width:100px;
  height:100px;
  top: 50%;
  left: 50%;
  transform: translate(-50%,-50%);
  border:1px solid silver;

  position:absolute;
}

test{position:relative;}

.test div{
  position:absolute;
  offset-path: path("M97.78,49.76a49.76,49.76,0,0,0,-49.76,-49.76c-22.33,0,-45.32,20.86,-47.52,35c-1.46,4.68,-2.23,19.13,61,21.5c-0.79,14.37,-43.76,9.63,-61.5,6.39a49.77,49.77,0,0,0,97.78,-13.09z");  
}

.cir-1 {
  width:20px;
  height:20px;
  border-radius: 50%;
  background:rgb(119, 30, 30);
  animation: move 3s ease-in-out infinite;

}
.cir-2 {
  width:30px;
  height:30px;
  border-radius: 50%;
  background-color: blueviolet;
  offset-distance: 10%;
  animation: move2 3s ease-in-out infinite;
}
.cir-3 {
  width:50px;
  height:50px;
  border-radius: 50%;
  background:cornflowerblue;
  offset-distance: 20%;
  animation: move3 3s ease-in-out infinite;
}
@keyframes move {
  100% { 
    offset-distance: 100%;
  }
}

@keyframes move2 {
  100% { 
    offset-distance: 110%;
  }
}

@keyframes move3 {
  100% { 
    offset-distance: 120%;
  }
}




svg{position:absolute;}
<div class="loading-wrap">
<svg viewBox="0 0 100 100">
  <path d="M97.78,49.76a49.76,49.76,0,0,0,-49.76,-49.76c-22.33,0,-45.32,20.86,-47.52,35c-1.46,4.68,-2.23,19.13,61,21.5c-0.79,14.37,-43.76,9.63,-61.5,6.39a49.77,49.77,0,0,0,97.78,-13.09z" fill="none" stroke="black"/>
</svg>
<div class="test">
  <div class="cir-1"></div>
  <div class="cir-2"></div>
  <div class="cir-3"></div>
</div>
</div>

UPDATE

If you require the animation to play in reverse, there are two solutions:

  1. Reverse the SVG path by using this path
    M97.78,49.76L97.78,49.8A49.77,49.77 0 0 10,62.89C17.74,66.13 60.71,70.87 61.5,56.5C-1.73,54.123 -0.96,39.68 0.5,35C2.7,20.86 25.69,0 48.02,0A49.76,49.76 0 0 197.78,49.76z
    instead.

.loading-wrap {
  width:100px;
  height:100px;
  top: 50%;
  left: 50%;
  transform: translate(-50%,-50%);  
  position:absolute;
  border:1px solid silver;
}

test{position:relative;}

.test div{
  position:absolute;
  offset-path: path("M97.78,49.76L97.78,49.8A49.77,49.77 0 0 10,62.89C17.74,66.13 60.71,70.87 61.5,56.5C-1.73,54.123 -0.96,39.68 0.5,35C2.7,20.86 25.69,0 48.02,0A49.76,49.76 0 0 197.78,49.76z");  
}

.cir-1 {
  width:20px;
  height:20px;
  border-radius: 50%;
  background:rgb(119, 30, 30);
  animation: move 3s ease-in-out infinite;

}
.cir-2 {
  width:30px;
  height:30px;
  border-radius: 50%;
  background-color: blueviolet;
  offset-distance: 10%;
  animation: move2 3s ease-in-out infinite;
}
.cir-3 {
  width:50px;
  height:50px;
  border-radius: 50%;
  background:cornflowerblue;
  offset-distance: 20%;
  animation: move3 3s ease-in-out infinite;
}
@keyframes move {
  100% {     
    offset-distance: 100%;
  }
}

@keyframes move2 {
  100% {     
    offset-distance: 110%;
  }
}

@keyframes move3 {
  100% { 
    offset-distance: 120%;
  }
}




svg{position:absolute;}
<div class="loading-wrap">
<svg viewBox="0 0 100 100">
  <path d="M97.78,49.76L97.78,49.8A49.77,49.77 0 0 10,62.89C17.74,66.13 60.71,70.87 61.5,56.5C-1.73,54.123 -0.96,39.68 0.5,35C2.7,20.86 25.69,0 48.02,0A49.76,49.76 0 0 197.78,49.76z" fill="none" stroke="black"/>
</svg>
<div class="test">
  <div class="cir-1"></div>
  <div class="cir-2"></div>
  <div class="cir-3"></div>
</div>
</div>

  1. You can use the same path but animate the divs to have negative offset distances.

.loading-wrap {
  width:100px;
  height:100px;
  top: 50%;
  left: 50%;
  transform: translate(-50%,-50%);
  border:1px solid silver;

  position:absolute;
}

test{position:relative;}

.test div{
  position:absolute;
  offset-path: path("M97.78,49.76a49.76,49.76,0,0,0,-49.76,-49.76c-22.33,0,-45.32,20.86,-47.52,35c-1.46,4.68,-2.23,19.13,61,21.5c-0.79,14.37,-43.76,9.63,-61.5,6.39a49.77,49.77,0,0,0,97.78,-13.09z");  
}

.cir-1 {
  width:20px;
  height:20px;
  border-radius: 50%;
  background:rgb(119, 30, 30);
  animation: move 3s ease-in-out infinite;

}
.cir-2 {
  width:30px;
  height:30px;
  border-radius: 50%;
  background-color: blueviolet;
  offset-distance: -10%;
  animation: move2 3s ease-in-out infinite;
}
.cir-3 {
  width:50px;
  height:50px;
  border-radius: 50%;
  background:cornflowerblue;
  offset-distance: -20%;
  animation: move3 3s ease-in-out infinite;
}
@keyframes move {
  100% { 
    offset-distance: -100%;
  }
}

@keyframes move2 {
  100% { 
    offset-distance: -110%;
  }
}

@keyframes move3 {
  100% { 
    offset-distance: -120%;
  }
}




svg{position:absolute;}
<div class="loading-wrap">
<svg viewBox="0 0 100 100">
  <path d="M97.78,49.76a49.76,49.76,0,0,0,-49.76,-49.76c-22.33,0,-45.32,20.86,-47.52,35c-1.46,4.68,-2.23,19.13,61,21.5c-0.79,14.37,-43.76,9.63,-61.5,6.39a49.77,49.77,0,0,0,97.78,-13.09z" fill="none" stroke="black"/>
</svg>
<div class="test">
  <div class="cir-1"></div>
  <div class="cir-2"></div>
  <div class="cir-3"></div>
</div>
</div>

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

Would you like to learn how to set an auto-play video as the background in a webpage section, similar to the one found on http://www8.hp.com/in/en/home.html?

I was browsing the HP-India website and noticed they have a cool autoplay video in the background of a section below the header. I would love to recreate something similar on my own website. Any tips on how to achieve this? ...

CSS - revealing additional submenu on hover

I'm currently working on customizing a Wordpress menu that includes classic menu items and their respective submenus. The issue I'm facing is that when I hover over an item with children, its submenu will display. However, I want to have a fixed ...

What is the method to set an element's height equivalent to the height of the entire screen?

I attempted using height: auto;, however, it did not produce the desired outcome. Do you have any suggestions or alternative solutions? ...

Contrasts between space and the greater than selector

Can you explain the distinction between selector 6 and selector 7 as outlined on the w3 website? Inquiring minds want to know. ...

When creating a FlipCard, you may encounter the error message "The object may be null" while using the document.querySelector() method

Having trouble creating a flipcard on Next.js with tsx. The querySelector('.cardflipper') doesn't seem to locate the object and I keep getting this error: "Possibly the object is null". Does anyone know a solution to help my method recognize ...

Office Outlook Client experiencing incorrect div width

I'm having trouble sending an email with HTML content because it's not displaying correctly in Microsoft Office Outlook when it comes to width. Any suggestions on how to fix this issue? <div style="width: 650px; border: 1px solid blue">hel ...

I am experiencing an issue wherein after using jquery's hover() function, the CSS :hover state is not

Following the jquery hover function, the css hover feature ceases to work. In my html, there are multiple svg elements. A jquery script is applied where hovering over a button at the bottom triggers all svg elements to change color to yellow (#b8aa85). S ...

What is the best way to eliminate the border around an image when including a hyperlink?

There seems to be a rectangle showing up outside the link that I would like to remove. How can I get rid of it? No Image <a href="~/Web Pages/Home.aspx" runat="server"> <img src="<%= ResolveUrl("~/Images/TestToday.png") %>" alt="No im ...

Troubleshooting border styling problems on an iPad for a table

I'm encountering a CSS issue specifically on iPad devices when rendering the HTML page. Oddly enough, everything appears fine on other browsers. The problem I'm facing is a small space between the cells in my tables as shown in this image: Stran ...

What is the best way to generate a CSS design with wavy patterns?

Check out the image below to see what I am attempting to create: https://i.sstatic.net/PlroF.png Here is my current code, but I need to make it more dynamic, similar to increasing the frequency rate of a sin or cosine wave. #wave { position: relativ ...

What is the best way to define my background image using markup language?

I'm facing a challenge with some code that I didn't write which includes a background-image. While I want to maintain the identical appearance, I prefer to set the image in my markup rather than CSS. However, I'm unsure of how to do this. T ...

Breaking free of the constraints of a 100% height container, UL escapes its

In both Chrome and Firefox, UL list items do not seem to adhere to the parent container's width of 100%. I attempted to use list-style-position: inside;, but unfortunately, that did not solve the issue: <html style="height: 100%"> <body styl ...

Show image details on hover?

I have six images displayed full width using a flex grid. I would like the image information (along with a visit button) to appear on hover, and the brightness of the image should decrease. I am struggling to position the information in the center of the i ...

Component rendering based on conditions is not working properly when using Next.js, especially on the initial load

While utilizing Ant Design and a Custom Stylesheet, I have encountered an issue where the style appears broken upon first load. However, if I navigate to another page and return to the original broken page, it displays correctly. This problem only occurs d ...

Can file input buttons be custom styled?

Since I am using Material-UI, the traditional methods are not working for me. I have a form with two buttons positioned next to each other. One button is an "Upload File" input for users to upload a file, and the other is a submit button. I want both butto ...

The Beginner's Guide to Mastering Ajax and Grails

As a newcomer to Grails and AJAX, I find myself struggling to understand the concept of AJAX with limited resources online. My current understanding is that in Grails, if I want to trigger a method in one of my controllers when a specific part of my HTML ...

Being required to design a distinct div for every article I am extracting from the API

In the midst of developing a website for my college project, I have successfully configured my news API to pull and display data using JavaScript. Currently, I am faced with the challenge of having to create separate div elements each time I want to add n ...

Tips for hiding website content on larger screens

Is there a way to hide website content on screen sizes over 1600px and display only a message image instead? ...

Enhancing Dropdown Functionality Using Jquery

Hey there, I am looking to create a dropdown list/menu similar to the one shown in this image: (a screenshot). Could you please guide me on how to achieve this? Can it be done using JQUERY? Thank you in advance, Andrea ...

The modal is functioning properly on Firefox and Internet Explorer, but it is experiencing issues

Having an issue with my modal not functioning properly in Chrome. When I click on it, only the background fades and both the before and after content load in the Chrome Dev tools simultaneously with no visible content in between. Here is a link to the Cod ...