SVG - It is possible to add stroke-dasharray Gradient or transparent form one side [duplicate]

人走茶凉 提交于 2019-12-22 05:58:30

问题


I have created an SVG animation in which I am allowing stroke-dasharray to move. Is it possible that I can add a gradient to the tail of stroke-dasharray and keep one side transparent as you can see in the example?

.svg-main {
    width: 700px;
    margin: 30px auto;
    position: relative;
}
svg#svga {
    position: absolute;
    top: 0;
    left: auto;
    bottom: auto;
    right: auto;
}

.st2{fill:none;stroke:#cccccc;stroke-width:6;}
.sd1{fill:none;stroke:#000000; stroke-width:6;stroke-linecap:round;}
.circ{fill:#000000; }
<div class="svg-main">
<svg id="svga" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"
	 width="300px" height="200px" viewBox="0 0 685 310">
  <g class="st2">
	<path id="loop-normal" d="M343.6,156.5c11,15.9,104.6,147.2,181.9,147.6c0.1,0,0.8,0,1,0c82.1-0.3,148.6-67,148.6-149.2
	c0-82.4-66.8-149.2-149.2-149.2c-77.2,0-170.8,131-182.2,147.5c-0.8,1.1-1.6,2.3-2.1,3.1c-10.6,15.3-104.8,147.8-182.4,147.8
	C76.7,304.2,9.9,237.4,9.9,155S76.7,5.8,159.1,5.8c77.2,0,170.7,130.9,182.2,147.5C342.1,154.4,342.9,155.6,343.6,156.5z"/>
  </g>
	<use class="sd1" stroke-dasharray="200 1710" xlink:href="#loop-normal">
		<animate attributeName="stroke-dashoffset"
	    	from="200"  to="-1710"
	    	begin="0s" dur="10s"
	    	repeatCount="indefinite"/>  
	</use>

	<circle id="plug" class="circ" cx="0" cy="0" r="7"/> 
	<animateMotion
		xlink:href="#plug"
	  	dur="10s"
		rotate="auto"
		repeatCount="indefinite"
		calcMode="linear"
		keyTimes="0;1"    
		keyPoints="0;1">
		<mpath xlink:href="#loop-normal"/>
	</animateMotion> 
</svg>
</div>

回答1:


Please refer this

.svg-main {
    width: 700px;
    margin: 30px auto;
    position: relative;
}
svg#svga {
    position: absolute;
    top: 0;
    left: auto;
    bottom: auto;
    right: auto;
}

.st2{fill:none;stroke:#cccccc;stroke-width:6;}
.sd1{fill:none; stroke-width:6;stroke-linecap:round;}
.circ{fill:#000000; }
<div class="svg-main">
   
<svg id="svga" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"
	 width="300px" height="200px" viewBox="0 0 685 310">
    <defs>
    <linearGradient id="gradient" x1="0%" y1="0%" x2="0%" y2="100%">
      <stop offset="0%" stop-color="#000000" />
      <stop offset="100%" stop-color="#ffffff" />
    </linearGradient>
  </defs>
  <g class="st2" >
	<path id="loop-normal" d="M343.6,156.5c11,15.9,104.6,147.2,181.9,147.6c0.1,0,0.8,0,1,0c82.1-0.3,148.6-67,148.6-149.2
	c0-82.4-66.8-149.2-149.2-149.2c-77.2,0-170.8,131-182.2,147.5c-0.8,1.1-1.6,2.3-2.1,3.1c-10.6,15.3-104.8,147.8-182.4,147.8
	C76.7,304.2,9.9,237.4,9.9,155S76.7,5.8,159.1,5.8c77.2,0,170.7,130.9,182.2,147.5C342.1,154.4,342.9,155.6,343.6,156.5z"/>
  </g>
	<use class="sd1" stroke="url(#gradient)" stroke-dasharray="200 1710" xlink:href="#loop-normal">
		<animate attributeName="stroke-dashoffset"
	    	from="200"  to="-1710"
	    	begin="0s" dur="10s"
	    	repeatCount="indefinite"/>  
	</use>

	<circle id="plug" class="circ" cx="0" cy="0" r="7"/> 
  
	<animateMotion
		xlink:href="#plug"
	  	dur="10s"
		rotate="auto"
		repeatCount="indefinite"
		calcMode="linear"
		keyTimes="0;1"    
		keyPoints="0;1">
		<mpath xlink:href="#loop-normal"/>
	</animateMotion> 
</svg>
</div>


来源:https://stackoverflow.com/questions/51417587/svg-it-is-possible-to-add-stroke-dasharray-gradient-or-transparent-form-one-si

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!