Fill custom SVG image using percentage value

╄→尐↘猪︶ㄣ 提交于 2019-12-18 04:27:10

问题


I want to fill the custom SVG image with percentage value in Angular 6 using typescript or using CSS.

Is there any tool available for that?

Custom image can be anything like $, gear icon, thumb etc.

Any help would be appreciated.


回答1:


The simplest method is probably with a linear gradient.

function setProgress(amt)
{
  amt = (amt < 0) ? 0 : (amt > 1) ? 1 : amt;
  document.getElementById("stop1").setAttribute("offset", amt);
  document.getElementById("stop2").setAttribute("offset", amt);
}


setProgress(0.25);
<svg width="400" height="400">
  <defs>
    <linearGradient id="progress" x1="0" y1="1" x2="0" y2="0">
      <stop id="stop1" offset="0" stop-color="blue"/>
      <stop id="stop2" offset="0" stop-color="lightblue"/>
    </linearGradient>
  </defs>

  <circle id="my-shape" cx="200" cy="200" r="200" fill="url(#progress)"/>
</svg>


来源:https://stackoverflow.com/questions/51718987/fill-custom-svg-image-using-percentage-value

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