I want to create some decoration for my website and this is the svg I have:
svg image
<svg width="156" height="142" viewBox="0 0 156 142" fill="none" xmlns="http://www.w3.org/2000/svg">
<g>
<path d="M144.094 67.4748C144.094 75.9193 142.43 84.2811 139.197 92.0827C135.965 99.8842 131.226 106.973 125.253 112.943C119.28 118.913 112.189 123.649 104.385 126.879C96.5816 130.109 88.2177 131.771 79.7716 131.768C44.2485 131.768 12.9238 101.745 12.9238 66.1794C12.9238 30.6139 48.0205 0.410156 83.5437 0.410156C119.067 0.410156 144.094 31.942 144.094 67.4748Z" fill="#E1E8EB"/>
<path d="M78.6071 106.451C99.7205 106.451 116.836 89.3382 116.836 68.2288C116.836 47.1194 99.7205 30.0068 78.6071 30.0068C57.4937 30.0068 40.3779 47.1194 40.3779 68.2288C40.3779 89.3382 57.4937 106.451 78.6071 106.451Z" fill="#FF7C04"/>
<path d="M2.42712 52.3071C2.42712 52.3071 -8.97112 118.683 54.695 140.344" stroke="#343A40" stroke-width="2" stroke-miterlimit="10" stroke-linecap="round"/>
<path d="M125.151 1.63965C126.644 1.63965 157.148 26.1207 154.147 66.048" stroke="#343A40" stroke-width="2" stroke-miterlimit="10" stroke-linecap="round"/>
</g>
</svg>
As you can see there is two curved lines around the two circles. I want those lines to be rotating around circles indefinitely. Could someone guide me on the correct approach to implement this effect? Thank you!
I tried using css transform: rotate();
but I was unsucussfull.
3
Answers
An easy solution would be to use the css animation-feature (link to the documenation), than you just need to create 2 keyframes for the animation. The first one (0% of the animation-time) with no rotation and the second one (100% of the animation-time).
In the
animation
property you just need to sethow long the rotation should take and some other properties.Here a working demo:
Although your svg code is correct I opted for a simplified version.
Please observe that the outer circle has a
stroke-dasharray
attribute.The stroke-dasharray attribute is a presentation attribute defining the pattern of dashes and gaps used to paint the outline of the shape.
The total length of the stroke is 483 so the stroke-dasharray="120.75" which is 1/4 of the total length (2 * stroke + 2 * gaps).
For the animation I’m animating the stroke-dashoffset from 241.5 (half total length) to 0.
The stroke-dashoffset attribute is a presentation attribute defining an offset on the rendering of the associated dash array.
Set
pathLength="4"
on thecircle
(or path) to divide it into 4 segments and avoid doing any calculationsUse SVG SMIL animation to avoid using any CSS