简体   繁体   English

SVG路径填充动画

[英]Svg path fill with animation

I have a path which is similar to circle. 我有一条类似于圆的路径。 The task is to fill the path with a color with animation. 任务是用动画的颜色填充路径。 The fill animation should be in circle manner and not from top to bottom or bottom to top. 填充动画应为圆形,而不是从上到下或从下到上。

my svg code is : 我的svg代码是:

 <svg id="svg_circle" width="100%" height="100%" xmlns="http://www.w3.org/2000/svg" viewBox = '0 0 450 400'> <g class="svg_circle" transform = "translate(0,0)"> <path class="path" stroke="#F0F0F0" fill="#fff" stroke-width="1" opacity="1" d="m-0.25,238.11061l88.59461,-82.21665l87.56445,86.40604l-33.99561,0.52367c2.72107,17.03346 46.55824,67.96739 105.37633,63.99055c70.95792,-4.79765 101.17847,-64.19902 103.74816,-97.50561c7.13262,-92.44812 -81.66575,-121.29229 -115.80064,-115.90062c-119.13463,18.8176 -96.38311,112.29843 -96.38311,112.29843l-50.54082,-49.76652l-46.48973,43.1249c-12.30406,-104.7234 83.23188,-194.53124 191.25985,-198.17803c97.87838,-3.30416 202.62703,53.17701 213.76024,178.57248c16.06879,180.98587 -165.14043,220.64431 -208.6094,218.37164c-143.15297,-7.48456 -189.38275,-115.91408 -199.33787,-158.14925l-39.14646,-1.57102z" id="svg_1"> <animate id="project_anim1" attributeName="fill" from="#fff" to="#4DAF4C" begin="1s" dur="1s" fill="freeze" repeatCount="1"></animate> </path> </g> </svg> 

The common "dasharray" line drawing technique would work for you, in combination with using the arrow shape as a mask. 结合使用箭头形状作为遮罩,可以使用常见的“ dasharray”线条绘制技术。

This technique is described in this SO question 该技术问题对此技术进行了描述

However, since the head of your arrow shape overlaps the tail, to get a "perfect" result, you may have to divide the sweep into two parts. 但是,由于箭头形状的头部与尾部重叠,因此要获得“完美”的效果,可能必须将扫掠分为两部分。 You would draw the tail part with a tail mask, and then the second half of the shape (including the arrow head) with a separate mask. 您将使用尾部蒙版绘制尾部,然后使用单独的蒙版绘制形状的后半部分(包括箭头)。

Here's a rough imperfect version showing the technique. 这是显示该技术的不完美版本。

 <svg id="svg_circle" width="100%" height="100%" xmlns="http://www.w3.org/2000/svg" viewBox = '0 0 450 400'> <defs> <path id="arrow" stroke="#F0F0F0" fill="none" stroke-width="1" opacity="1" d="m-0.25,238.11061l88.59461,-82.21665l87.56445,86.40604l-33.99561,0.52367c2.72107,17.03346 46.55824,67.96739 105.37633,63.99055c70.95792,-4.79765 101.17847,-64.19902 103.74816,-97.50561c7.13262,-92.44812 -81.66575,-121.29229 -115.80064,-115.90062c-119.13463,18.8176 -96.38311,112.29843 -96.38311,112.29843l-50.54082,-49.76652l-46.48973,43.1249c-12.30406,-104.7234 83.23188,-194.53124 191.25985,-198.17803c97.87838,-3.30416 202.62703,53.17701 213.76024,178.57248c16.06879,180.98587 -165.14043,220.64431 -208.6094,218.37164c-143.15297,-7.48456 -189.38275,-115.91408 -199.33787,-158.14925l-39.14646,-1.57102z" id="svg_1"/> <clipPath id="arrow-clip" clipPathUnits="userSpaceOnUse"> <use xlink:href="#arrow"/> </clipPath> </defs> <g clip-path="url(#arrow-clip)"> <circle cx="244" cy="200" r="158" transform="rotate(-164,244,200)" fill="none" stroke="#4DAF4C" stroke-width="175" stroke-dasharray="993 993"> <animate attributeName="stroke-dashoffset" from="993" to="0" begin="1s" dur="1s" fill="freeze" repeatCount="1"/> </circle> </g> <use xlink:href="#arrow"/> </svg> 

Here we are animating a really thick green line, but using your shape as a clipping path so it conforms to the shape you want. 在这里,我们为一条非常粗的绿线设置了动画,但是将您的形状用作剪切路径,使其符合您想要的形状。

But as I mentioned, the section where the head overlaps the end of the tail is not perfect, so you may need to divide the animation into two parts as described above. 但是正如我提到的,头部与尾巴末端重叠的部分并不完美,因此您可能需要如上所述将动画分为两部分。

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

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