gpt4 book ai didi

css - 旋转 SVG stroke-dasharray 的破折号

转载 作者:行者123 更新时间:2023-12-02 04:35:15 25 4
gpt4 key购买 nike

我想为 SVG stroke-dasharray 的各个破折号的旋转设置动画,有人知道怎么做吗?

我意识到我可以使用 CSS 的 transform:rotate() 旋转 SVG 元素的整个对象,但是有什么方法可以旋转单个破折号吗?我也意识到我可以使用单个元素重新创建它并旋转它们,但出于性能和简洁的原因,这不是我想要做的

Here's a demo如果你想拥有一个。我希望方 block 在它们的位置上保持直立,而不是在绕着圆形路径旋转时旋转。我正在寻找重新创建 this gif

附言我知道圆圈没有完全对齐,I asked about that before

最佳答案

我做了 sample 。

http://jsdo.it/defghi1977/sQOc

Robert Longson 的“标记”方法非常好!谢谢!

<?xml version="1.0" standalone="no"?>
<svg width="400px" height="400px" viewBox="-200 -200 400 400" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" style="background-color:black;">
<defs>
<rect id="markerShape" x="-1" y="-1" width="2" height="2" fill="yellow">
<animateTransform attributeName="transform" type="rotate" to="360,0,0" begin="0s" dur="30s" repeatCount="indefinite"/>
</rect>

<marker id="marker1" markerUnits="strokeWidth" viewBox="-1 -1 2 2" overflow="visible" markerWidth="1" markerHeight="1">
<use xlink:href="#markerShape" transform="scale(0.02,0.02)"/><!--NOTE: =1/50-->
<animate attributeName="orient" from="0" to="-30" begin="0s" dur="5s" repeatCount="indefinite"/>
</marker>
<marker id="marker2" markerUnits="strokeWidth" viewBox="-1 -1 2 2" overflow="visible" markerWidth="1" markerHeight="1">
<use xlink:href="#markerShape" transform="scale(0.01428,0.01428)"/><!--NOTE: =1/70-->
<animate attributeName="orient" from="0" to="-60" begin="0s" dur="5s" repeatCount="indefinite"/>
</marker>
<marker id="marker3" markerUnits="strokeWidth" viewBox="-1 -1 2 2" overflow="visible" markerWidth="1" markerHeight="1">
<use xlink:href="#markerShape" transform="scale(0.01111,0.01111)"/><!--NOTE: =1/90-->
<animate attributeName="orient" from="0" to="-90" begin="0s" dur="5s" repeatCount="indefinite"/>
</marker>
<marker id="marker4" markerUnits="strokeWidth" viewBox="-1 -1 2 2" overflow="visible" markerWidth="1" markerHeight="1">
<use xlink:href="#markerShape" transform="scale(0.00909,0.00909)"/><!--NOTE: =1/110-->
<animate attributeName="orient" from="0" to="-120" begin="0s" dur="5s" repeatCount="indefinite"/>
</marker>
<marker id="marker5" markerUnits="strokeWidth" viewBox="-1 -1 2 2" overflow="visible" markerWidth="1" markerHeight="1">
<use xlink:href="#markerShape" transform="scale(0.007692,0.007692)"/><!--NOTE: =1/130-->
<animate attributeName="orient" from="0" to="-150" begin="0s" dur="5s" repeatCount="indefinite"/>
</marker>
<marker id="marker6" markerUnits="strokeWidth" viewBox="-1 -1 2 2" overflow="visible" markerWidth="1" markerHeight="1">
<use xlink:href="#markerShape" transform="scale(0.00666,0.00666)"/><!--NOTE: =1/150-->
<animate attributeName="orient" from="0" to="-180" begin="0s" dur="5s" repeatCount="indefinite"/>
</marker>
<marker id="marker7" markerUnits="strokeWidth" viewBox="-1 -1 2 2" overflow="visible" markerWidth="1" markerHeight="1">
<use xlink:href="#markerShape" transform="scale(0.00588,0.00588)"/><!--NOTE: =1/180-->
<animate attributeName="orient" from="0" to="-210" begin="0s" dur="5s" repeatCount="indefinite"/>
</marker>

<polygon id="basicShape" fill="none" points="
0,1
0.5,0.86603
0.86603,0.5
1,0
0.86603,-0.5
0.5,-0.86603
0,-1
-0.5,-0.86603
-0.86603,-0.5
-1,0
-0.86603,0.5
-0.5,0.86603"
/>
</defs>

<g>
<use xlink:href="#basicShape" transform="scale(50,50)" stroke-width="14" marker-mid="url(#marker1)" marker-start="url(#marker1)"/>
<animateTransform attributeName="transform" type="rotate" to="30,0,0" begin="0s" dur="5s" repeatCount="indefinite"/>
</g>
<g>
<use xlink:href="#basicShape" transform="scale(70,70)" stroke-width="15" marker-mid="url(#marker2)" marker-start="url(#marker2)"/>
<animateTransform attributeName="transform" type="rotate" to="60,0,0" begin="0s" dur="5s" repeatCount="indefinite"/>
</g>
<g>
<use xlink:href="#basicShape" transform="scale(90,90)" stroke-width="16" marker-mid="url(#marker3)" marker-start="url(#marker3)"/>
<animateTransform attributeName="transform" type="rotate" to="90,0,0" begin="0s" dur="5s" repeatCount="indefinite"/>
</g>
<g>
<use xlink:href="#basicShape" transform="scale(110,110)" stroke-width="17" marker-mid="url(#marker4)" marker-start="url(#marker4)"/>
<animateTransform attributeName="transform" type="rotate" to="120,0,0" begin="0s" dur="5s" repeatCount="indefinite"/>
</g>
<g>
<use xlink:href="#basicShape" transform="scale(130,130)" stroke-width="18" marker-mid="url(#marker5)" marker-start="url(#marker5)"/>
<animateTransform attributeName="transform" type="rotate" to="150,0,0" begin="0s" dur="5s" repeatCount="indefinite"/>
</g>
<g>
<use xlink:href="#basicShape" transform="scale(150,150)" stroke-width="19" marker-mid="url(#marker6)" marker-start="url(#marker6)"/>
<animateTransform attributeName="transform" type="rotate" to="180,0,0" begin="0s" dur="5s" repeatCount="indefinite"/>
</g>
<g>
<use xlink:href="#basicShape" transform="scale(170,170)" stroke-width="21" marker-mid="url(#marker7)" marker-start="url(#marker7)"/>
<animateTransform attributeName="transform" type="rotate" to="210,0,0" begin="0s" dur="5s" repeatCount="indefinite"/>
</g>
</svg>

关于css - 旋转 SVG stroke-dasharray 的破折号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22120426/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com