javascript - 使用百分比值填充自定义 SVG 图像

标签 javascript css typescript svg angular6

我想使用 typescript 或 CSS 在 Angular 6 中使用百分比值填充自定义 SVG 图像。

是否有任何可用的工具?

自定义图像可以是 $、齿轮图标、拇指等任何东西。

如有任何帮助,我们将不胜感激。

See this image

最佳答案

最简单的方法可能是线性渐变。

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>

关于javascript - 使用百分比值填充自定义 SVG 图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51718987/

相关文章:

javascript - 将FileReader结果的编码更改为UTF8

javascript - 如何测试包含异步函数的nodejs导出

javascript - 在 React 中删除 body 的边距

javascript - 将其中包含文本的 div 附加到更大的 div 中

html - 由于高度 :100%,页脚位置错误

javascript - 如何正确地将 MSAL(用于 js 的 Microsoft 身份验证库)导入并使用到 typescript react 单页应用程序中?

javascript - 当给定对象添加新属性时,有没有办法让 Javascript 抛出错误?

javascript - 输入文本字段触摸后调用相同的功能

css - 如何更改 wordpress 中只有一页的 css?

javascript - Typescript + Google Maps API + infobox.js 未捕获类型错误 : InfoBox is not a constructor