如何使用 SVG 径向动画循环颜色并保持边缘透明度?
How can I loop colors and maintain edge transparency with an SVG radial animation?
我有一个圆盘形 SVG,我想在其中应用一组从中心向外辐射的颜色,同时保持边缘(即停止不透明度)透明度,类似于如果该对象没有应用动画。
以下是动画版的主要障碍:
不保留边缘透明度。在某些情况下,我可能会通过覆盖一个相似的形状来解决这个问题,以适应边缘透明度,其颜色与目标对象的背景颜色互补——但在这种情况下,对象位于渐变之上。
循环重置为配置值 values="1%; ..."
,而不是平滑 looping/cycling 颜色。不确定如何解决这个问题,或者是否可以使用径向动画。
提前感谢任何thoughts/recommendations!
<div style="background: linear-gradient(#231f20 0%, #231f20 21%, rgba(31, 28, 29, 0.89) 49%, rgba(20, 18, 18, 0.57) 74%, rgba(1, 1, 1, 0.02) 99%, rgba(0, 0, 0, 0) 100%);">
<svg viewBox="0 0 10 10" xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink" width="300" style="display:inline-block;">
<defs>
<radialGradient id="gradient">
<stop offset="0%" stop-color="#d6d2c4"/>
<stop offset="24%" stop-color="#ffd600"/>
<stop offset="42%" stop-color="#a6cd57"/>
<stop offset="61%" stop-color="#f8971f"/>
<stop offset="100%" stop-color="#f8971f" stop-opacity="0"/>
</radialGradient>
</defs>
<!-- radial gradient animation -->
<circle cx="5" cy="5" r="4" fill="url('#gradient')" />
</svg>
<svg viewBox="0 0 10 10" xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink" width="300" style="display:inline-block;">
<defs>
<radialGradient id="gradientAnimate">
<stop offset="0%" stop-color="#d6d2c4"/>
<stop offset="10%" stop-color="#ffd600"/>
<stop offset="20%" stop-color="#a6cd57"/>
<stop offset="30%" stop-color="#f8971f"/>
<stop offset="40%" stop-color="#f8971f"/>
<stop offset="50%" stop-color="#d6d2c4"/>
<stop offset="70%" stop-color="#ffd600"/>
<stop offset="80%" stop-color="#a6cd57"/>
<stop offset="90%" stop-color="#f8971f"/>
<stop offset="100%" stop-color="#f8971f" stop-opacity="0"/>
<animate attributeName="r" dur="5s" repeatCount="indefinite"
values="50%; 100%; 300%" />
</radialGradient>
</defs>
<!-- radial gradient animation -->
<circle cx="5" cy="5" r="4" fill="url('#gradientAnimate')" />
</svg>
</div>
您的问题的解决方案是应用蒙版:一个从白到黑的径向渐变圆:
<div style="background: linear-gradient(#231f20 0%, #231f20 21%, rgba(31, 28, 29, 0.89) 49%, rgba(20, 18, 18, 0.57) 74%, rgba(1, 1, 1, 0.02) 99%, rgba(0, 0, 0, 0) 100%);">
<svg viewBox="0 0 10 10" xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink" width="300" style="display:inline-block;">
<defs>
<radialGradient id="gradient">
<stop offset="0%" stop-color="#d6d2c4"/>
<stop offset="24%" stop-color="#ffd600"/>
<stop offset="42%" stop-color="#a6cd57"/>
<stop offset="61%" stop-color="#f8971f"/>
<stop offset="100%" stop-color="#f8971f" stop-opacity="0"/>
</radialGradient>
</defs>
<!-- radial gradient animation -->
<circle cx="5" cy="5" r="4" fill="url('#gradient')" />
</svg>
<svg viewBox="0 0 10 10" xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink" width="300" style="display:inline-block;">
<defs>
<radialGradient id="rg">
<stop offset="50%" stop-color="#fff"></stop>
<stop offset="100%" stop-color="#000"></stop>
</radialGradient>
<mask id="maskCirc">
<circle cx="5" cy="5" r="4" fill="url(#rg)"></circle>
</mask>
<radialGradient id="gradientAnimate">
<stop offset="0%" stop-color="#d6d2c4"/>
<stop offset="10%" stop-color="#ffd600"/>
<stop offset="20%" stop-color="#a6cd57"/>
<stop offset="30%" stop-color="#f8971f"/>
<stop offset="40%" stop-color="#f8971f"/>
<stop offset="50%" stop-color="#d6d2c4"/>
<stop offset="70%" stop-color="#ffd600"/>
<stop offset="80%" stop-color="#a6cd57"/>
<stop offset="90%" stop-color="#f8971f"/>
<stop offset="100%" stop-color="#f8971f" stop-opacity="0"/>
<animate attributeName="r" dur="5s" repeatCount="indefinite"
values="50%; 100%; 300%" />
</radialGradient>
</defs>
<!-- radial gradient animation -->
<circle cx="5" cy="5" r="4" fill="url('#gradientAnimate')" style="mask: url(#maskCirc);"/>
</svg>
</div>
我有一个圆盘形 SVG,我想在其中应用一组从中心向外辐射的颜色,同时保持边缘(即停止不透明度)透明度,类似于如果该对象没有应用动画。
以下是动画版的主要障碍:
不保留边缘透明度。在某些情况下,我可能会通过覆盖一个相似的形状来解决这个问题,以适应边缘透明度,其颜色与目标对象的背景颜色互补——但在这种情况下,对象位于渐变之上。
循环重置为配置值
values="1%; ..."
,而不是平滑 looping/cycling 颜色。不确定如何解决这个问题,或者是否可以使用径向动画。
提前感谢任何thoughts/recommendations!
<div style="background: linear-gradient(#231f20 0%, #231f20 21%, rgba(31, 28, 29, 0.89) 49%, rgba(20, 18, 18, 0.57) 74%, rgba(1, 1, 1, 0.02) 99%, rgba(0, 0, 0, 0) 100%);">
<svg viewBox="0 0 10 10" xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink" width="300" style="display:inline-block;">
<defs>
<radialGradient id="gradient">
<stop offset="0%" stop-color="#d6d2c4"/>
<stop offset="24%" stop-color="#ffd600"/>
<stop offset="42%" stop-color="#a6cd57"/>
<stop offset="61%" stop-color="#f8971f"/>
<stop offset="100%" stop-color="#f8971f" stop-opacity="0"/>
</radialGradient>
</defs>
<!-- radial gradient animation -->
<circle cx="5" cy="5" r="4" fill="url('#gradient')" />
</svg>
<svg viewBox="0 0 10 10" xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink" width="300" style="display:inline-block;">
<defs>
<radialGradient id="gradientAnimate">
<stop offset="0%" stop-color="#d6d2c4"/>
<stop offset="10%" stop-color="#ffd600"/>
<stop offset="20%" stop-color="#a6cd57"/>
<stop offset="30%" stop-color="#f8971f"/>
<stop offset="40%" stop-color="#f8971f"/>
<stop offset="50%" stop-color="#d6d2c4"/>
<stop offset="70%" stop-color="#ffd600"/>
<stop offset="80%" stop-color="#a6cd57"/>
<stop offset="90%" stop-color="#f8971f"/>
<stop offset="100%" stop-color="#f8971f" stop-opacity="0"/>
<animate attributeName="r" dur="5s" repeatCount="indefinite"
values="50%; 100%; 300%" />
</radialGradient>
</defs>
<!-- radial gradient animation -->
<circle cx="5" cy="5" r="4" fill="url('#gradientAnimate')" />
</svg>
</div>
您的问题的解决方案是应用蒙版:一个从白到黑的径向渐变圆:
<div style="background: linear-gradient(#231f20 0%, #231f20 21%, rgba(31, 28, 29, 0.89) 49%, rgba(20, 18, 18, 0.57) 74%, rgba(1, 1, 1, 0.02) 99%, rgba(0, 0, 0, 0) 100%);">
<svg viewBox="0 0 10 10" xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink" width="300" style="display:inline-block;">
<defs>
<radialGradient id="gradient">
<stop offset="0%" stop-color="#d6d2c4"/>
<stop offset="24%" stop-color="#ffd600"/>
<stop offset="42%" stop-color="#a6cd57"/>
<stop offset="61%" stop-color="#f8971f"/>
<stop offset="100%" stop-color="#f8971f" stop-opacity="0"/>
</radialGradient>
</defs>
<!-- radial gradient animation -->
<circle cx="5" cy="5" r="4" fill="url('#gradient')" />
</svg>
<svg viewBox="0 0 10 10" xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink" width="300" style="display:inline-block;">
<defs>
<radialGradient id="rg">
<stop offset="50%" stop-color="#fff"></stop>
<stop offset="100%" stop-color="#000"></stop>
</radialGradient>
<mask id="maskCirc">
<circle cx="5" cy="5" r="4" fill="url(#rg)"></circle>
</mask>
<radialGradient id="gradientAnimate">
<stop offset="0%" stop-color="#d6d2c4"/>
<stop offset="10%" stop-color="#ffd600"/>
<stop offset="20%" stop-color="#a6cd57"/>
<stop offset="30%" stop-color="#f8971f"/>
<stop offset="40%" stop-color="#f8971f"/>
<stop offset="50%" stop-color="#d6d2c4"/>
<stop offset="70%" stop-color="#ffd600"/>
<stop offset="80%" stop-color="#a6cd57"/>
<stop offset="90%" stop-color="#f8971f"/>
<stop offset="100%" stop-color="#f8971f" stop-opacity="0"/>
<animate attributeName="r" dur="5s" repeatCount="indefinite"
values="50%; 100%; 300%" />
</radialGradient>
</defs>
<!-- radial gradient animation -->
<circle cx="5" cy="5" r="4" fill="url('#gradientAnimate')" style="mask: url(#maskCirc);"/>
</svg>
</div>