描边效果的SVG渐变
P粉193307465
P粉193307465 2023-08-29 09:30:52
[CSS3讨论组]
<p>我发现了这段代码</p> <pre class="brush:php;toolbar:false;">&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; viewBox=&quot;-1 -1 34 34&quot;&gt; &lt;circle cx=&quot;16&quot; cy=&quot;16&quot; r=&quot;15.9155&quot; class=&quot;progress-bar__background&quot; /&gt; &lt;circle cx=&quot;16&quot; cy=&quot;16&quot; r=&quot;15.9155&quot; class=&quot;progress-bar__progress js-progress-bar&quot;/&gt; &lt;/svg&gt;</pre> <pre class="brush:php;toolbar:false;">$progress-bar-stroke-width: 1.8; $progress-bar-size: 300px; svg { height: $progress-bar-size; transform: rotate(-90deg); width: $progress-bar-size; } .progress-bar__background { fill: none; stroke: #e2eff0; stroke-width: $progress-bar-stroke-width; } .progress-bar__progress { fill: none; stroke: #78bec7; stroke-dasharray: 100 100; stroke-dashoffset: 100; stroke-linecap: round; stroke-width: $progress-bar-stroke-width; transition: stroke-dashoffset 1s ease-in-out; }</pre> <pre class="brush:php;toolbar:false;">var percentageComplete = 0.6; var strokeDashOffsetValue = 100 - (percentageComplete * 100); var progressBar = $(&quot;.js-progress-bar&quot;); progressBar.css(&quot;stroke-dashoffset&quot;, strokeDashOffsetValue);</pre> <p>但是我不知道如何处理svg,有人可以帮我吗,如何将那个蓝绿色替换成渐变色,像conic-gradient(red, yellow, green - 确切的这三种颜色)?</p>
P粉193307465
P粉193307465

全部回复(1)
P粉908643611

在SVG中,您可以使用<linearGradient><radialGradient>。您正在创建一个进度条,所以根据布局,径向渐变可能是创建“锥形渐变”(加引号!)的选项,但是使用起来真的很烦人。

一个很好的替代内置渐变的方法可能是结合SVG和CSS。您可以将CSS样式应用于嵌入的SVG元素。只要您只需要一个可应用于SVG元素的锥形渐变,然后进行遮罩,以便它只显示在描边或其他地方。这是一个示例:

svg {
  display: block;
  background-image: conic-gradient(from 180deg, green, orange, red);
}
<svg width="300" xmlns="http://www.w3.org/2000/svg"
  viewBox="0 0 100 100">
  <defs>
    <mask id="m1">
      <rect width="100" height="100" fill="white" />
      <circle transform="rotate(120 50 50)" cx="50"
        cy="50" r="45" stroke="black" stroke-width="5"
        fill="none" stroke-dasharray="300 360" pathLength="360" />
    </mask>
  </defs>
  <rect width="100" height="100" fill="white" mask="url(#m1)" />
</svg>
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号