简体   繁体   English

SVG - 绕圆旋转的圆

[英]SVG - circle rotating around circle

I have two circles, one just an outline, and one filled in.我有两个圆圈,一个只是轮廓,一个是填充的。

 <svg width="300" height="300" style="border: 1px solid black"> <circle stroke="black" stroke-width="1" r="100" cx="150" cy="150" fill="white"></circle> <circle r="10" cx ="50" cy="150"></circle> </svg>

I want the filled-in circle to rotate around the other circle.我希望实心圆圈围绕另一个圆圈旋转。 How can I do this?我怎样才能做到这一点? A css/svg only solution would be great, as this will be a .svg file, not a .html file.仅使用 css/svg 的解决方案会很棒,因为这将是.svg文件,而不是.html文件。

So, I decided to try using only HTML and CSS for this.因此,我决定为此尝试仅使用 HTML 和 CSS 。

 .inner { margin: 0 auto; height: 250px; width: 250px; border-radius: 100%; border: 1px solid black; position: relative; }.outter { height: 20px; width: 20px; border-radius: 100%; background: black; position: absolute; top: 115px; left: 115px; animation: spin 5s linear infinite; } @keyframes spin { from { transform: rotate(0deg) translate(125px); } to { transform: rotate(360deg) translate(125px); } }
 <div class="inner"> <div class="outter"></div> </div>

Hope it helps.希望能帮助到你。 Regards问候

EDITED: Made with SVG.编辑:用 SVG 制成。

 .outter { transform-origin: 150px 150px; animation: spin 5s infinite linear; } @keyframes spin { from { transform: rotate(0deg); } to { transform: rotate(360deg); } }
 <svg width="300" height="300" style="border: 1px solid black"> <circle stroke="black" stroke-width="1" r="100" cx="150" cy="150" fill="white"></circle> <circle class="outter" r="10" cx ="50" cy="150"></circle> </svg>

You could also use a svg SMIL animation like <animateTransform>您也可以使用 svg SMIL animation 像<animateTransform>

 <svg width="300" height="300" style="border: 1px solid black"> <circle stroke="black" stroke-width="1" r="100" cx="150" cy="150" fill="white" /> <circle id="dot" r="10" cx="50" cy="150" /> <animateTransform href="#dot" attributeName="transform" type="rotate" from="0 150 150" to="360 150 150" dur="3s" repeatCount="indefinite" /> </svg>

The above <animateTransform> values translates to these transformation attributes:上面的<animateTransform>值转换为这些转换属性:

From

transform="rotate(0 150 150)"   

to

transform="rotate(360 150 150)"   

Unlike its css counterpart svg's rotate() accepts 3 arguments与其 ZC7A62​​8CBA22E28EB17B5F5C6AE2A266AZ 对应的 svg 的 rotate() 不同,它接受 3 arguments

  1. rotation angle (mandatory)旋转角度(强制)
  2. transform origin x变换原点 x
  3. transform origin y变换原点 y

This way we can define the pivot point – in this case the center of our circle/svg.通过这种方式,我们可以定义 pivot 点——在这种情况下,我们的圆/svg 的中心。

Probably the main benefit of SMIL animations: they will also play in <img> elements and background-images.可能是 SMIL 动画的主要好处:它们也可以在<img>元素和背景图像中播放。
This concept is often used for loading spinner svgs.这个概念通常用于加载微调器 svg。

i think you can use transform with transtition我认为您可以使用带有过渡的变换

circle{
transform: translate(20px,10px) ;
transition: transform 1s;

} }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM