Javascript 带有SVG的徽标中的动画半圆
我想用SVG制作这个图形。我可以使用Javascript 带有SVG的徽标中的动画半圆,javascript,html,svg,svg-animate,Javascript,Html,Svg,Svg Animate,我想用SVG制作这个图形。我可以使用标记,并且可以使用javascript操作SVG文档。如果可能的话,我更喜欢用SVG来完成这一切 这只是一个起点的想法。然后可以应用遮罩来隐藏和显示部分图形 <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"> <
标记,并且可以使用javascript操作SVG文档。如果可能的话,我更喜欢用SVG来完成这一切
这只是一个起点的想法。然后可以应用遮罩来隐藏和显示部分图形
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg xmlns="http://www.w3.org/2000/svg" width="100%" height="100%">
<circle cx="200" cy="200" r="100" fill="gray"/>
<rect x="100" y="200" height="101" width="201" fill="white">
<animateTransform attributeName="transform"
attributeType="XML"
type="rotate"
from="0 200 200"
to="360 200 200"
dur="5s"
repeatCount="indefinite"/>
</rect>
<circle cx="200" cy="200" r="90" fill="white"/>
</svg>
非常感谢@helderdarocha为我指明了正确的方向
<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
width="144px" height="144px" viewBox="0 0 144 144" enable-background="new 0 0 144 144">
<defs>
<clipPath id="rotation-top" clip-path="url(#top-half)">
<rect x="0" y="72" height="72" width="144">
<animateTransform attributeName="transform"
attributeType="XML"
type="rotate"
from="360 72 72"
to="0 72 72"
dur="3s"
repeatCount="indefinite">
</animateTransform>
</rect>
</clipPath>
<clipPath id="rotation-bottom" clip-path="url(#bottom-half)">
<rect x="0" y="0" height="72" width="144">
<animateTransform attributeName="transform"
attributeType="XML"
type="rotate"
from="360 72 72"
to="0 72 72"
dur="3s"
repeatCount="indefinite">
</animateTransform>
</rect>
</clipPath>
<clipPath id="top-half">
<rect x="0" y="0" height="72" width="144">
</rect>
</clipPath>
<clipPath id="bottom-half">
<rect x="0" y="72" height="72" width="144">
</rect>
</clipPath>
</defs>
<!-- background white -->
<circle opacity="0.56" fill="#FFFFFF" cx="72" cy="72" r="72"/>
<!-- back gray color -->
<circle cx="72" cy="72" r="49" stroke-width="6" stroke="#838588" fill-opacity="0.0"/>
<!-- foreground orange color -->
<circle
cx="72" cy="72" r="49"
stroke-width="6" stroke="#F68524" fill-opacity="0.0"
clip-path="url(#rotation-bottom)"
/>
<circle
cx="72" cy="72" r="49"
stroke-width="6" stroke="#F68524" fill-opacity="0.0"
clip-path="url(#rotation-top)"
/>
</svg>
对于跨浏览器动画,最好使用Javascript。(即不支持SMIL)。setInterval在所有浏览器中都非常健壮 例如,要连续旋转图元,可以使用:
function basicRotate()
{
var FPS=100 //----frames per second---
var angle = 0//---starting value---
function frame()
{
angle++
myElement.setAttribute("transform","rotate("+angle+" "+centetX+" "+centerY+")")
if (angle == 360)
angle=0
}
//---start interval timer---
var iT = setInterval(frame, 1000/FPS ) //---draw every 10ms ---
}
下面是一个简单的例子:
<svg height="200" width="200" viewBox="0 0 144 144">
<circle cx="72" cy="72" r="49" stroke-width="6" stroke="#F68524" fill="none"/>
<circle cx="72" cy="72" r="49"
stroke-width="6" stroke="#838588" fill="none">
<animate attributeName="stroke-dasharray" values="154 0;0 154" dur="1s" repeatCount="indefinite"/>
</circle>
</svg>
请参见。您已经走了多远?看起来我必须手动在路径数据中设置圆弧动画。。。我不这么认为,您应该能够使用SMIL来实现这一点。为弧路径的stroke dasharray属性设置动画。您总是可以在SVG中找到一种创造性的方法。我想象着画一条弧,然后通过位于中心的一个角旋转一个矩形。然后你会逐渐地覆盖半个圆圈。或者想出一些更好的形状来达到这样的效果。哇。看起来很棒!将你的答案标记为正确答案。我再过两天就不行了:(哇,太棒了。我不明白它在做什么。这些值代表什么?请注意,你的示例并不完全正确。当它循环时,不应该有闪光。它应该平滑地开始传播灰色而不是橙色。
<svg height="200" width="200" viewBox="0 0 144 144">
<circle cx="72" cy="72" r="49" stroke-width="6" stroke="#F68524" fill="none">
<animate attributeName="stroke" values="#838588;#F68524"
dur="2s" calcMode="discrete" repeatCount="indefinite"/>
</circle>
<circle cx="72" cy="72" r="49"
stroke-width="6" stroke="#838588" fill="none">
<animate attributeName="stroke-dasharray" values="154 0;0 154"
dur="1s" repeatCount="indefinite"/>
<animate attributeName="stroke" values="#F68524;#838588"
dur="2s" calcMode="discrete" repeatCount="indefinite"/>
</circle>
</svg>