gpt4 book ai didi

svg - 如何使用 svg 在矩形周围创建 "glow"?

转载 作者:行者123 更新时间:2023-12-03 00:11:08 33 4
gpt4 key购买 nike

我有类似以下内容:

<svg id="svgLogo1" style="left:0; top:0; position:absolute"
width="980" height="80" viewBox="0 0 980 80"
xmlns="http://www.w3.org/2000/svg">
<rect x="0" y="5" width="980" height="54" rx="6" ry="6"
style="stroke-width:2; xstroke:#FFF; fill:#555"/>
</svg>

我想在其周围创建白色光芒。

有什么方法可以在 svg 中做到这一点吗?我环顾四周,我能找到的只是“阴影”,这并不是我真正想要的,因为我想要在矩形的所有四个边周围有一个阴影(发光)。

最佳答案

以下是一些提供不同类型效果的滤镜:

  • 阴影(带有轻微偏移的透明黑色阴影)
  • 黑光(具有固定颜色)
  • 对象色发光(采用应用对象的颜色)

一个例子:

有一个demo here .

代码:

<!-- a transparent grey drop-shadow that blends with the background colour -->
<filter id="shadow" width="1.5" height="1.5" x="-.25" y="-.25">
<feGaussianBlur in="SourceAlpha" stdDeviation="2.5" result="blur"/>
<feColorMatrix result="bluralpha" type="matrix" values=
"1 0 0 0 0
0 1 0 0 0
0 0 1 0 0
0 0 0 0.4 0 "/>
<feOffset in="bluralpha" dx="3" dy="3" result="offsetBlur"/>
<feMerge>
<feMergeNode in="offsetBlur"/>
<feMergeNode in="SourceGraphic"/>
</feMerge>
</filter>

<!-- a transparent grey glow with no offset -->
<filter id="black-glow">
<feColorMatrix type="matrix" values=
"0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
0 0 0 0.7 0"/>
<feGaussianBlur stdDeviation="2.5" result="coloredBlur"/>
<feMerge>
<feMergeNode in="coloredBlur"/>
<feMergeNode in="SourceGraphic"/>
</feMerge>
</filter>

<!-- a transparent glow that takes on the colour of the object it's applied to -->
<filter id="glow">
<feGaussianBlur stdDeviation="2.5" result="coloredBlur"/>
<feMerge>
<feMergeNode in="coloredBlur"/>
<feMergeNode in="SourceGraphic"/>
</feMerge>
</filter>

关于svg - 如何使用 svg 在矩形周围创建 "glow"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9630008/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com