【发布时间】:2021-12-26 06:41:21
【问题描述】:
我想模糊图像的角落,同时保留清晰的中心。 使用 css background-blur() 是没有问题的,因为 Firefox 不支持它。 在模糊的图像上添加清晰的图像,然后将第一个图像遮住也是不可行的,因为最后我想用 three.js 场景更改静态图像。
我尝试跟随this tutorial,但使用的是径向渐变,而不是固定条。
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<defs>
<filter id="blurlayer" width="100%" height="100%">
<feGaussianBlur stdDeviation="4" result="blur"/>
<radialGradient id="radialGradient" cx="50%" cy="50%" r="50%" fx="50%" fy="50%" result="mask">
<stop offset="0%" stop-color="white" stop-opacity="1" />
<stop offset="100%" stop-color="black" stop-opacity="0" />
</radialGradient>
<feComposite in="blur" in2="mask" operator="in" result="comp" />
<feMerge result="merge">
<feMergeNode in="SourceGraphic" />
<feMergeNode in="comp" />
</feMerge>
</filter>
</defs>
<image filter="url(#blurlayer)" x="0" y="0" width="100%" height="100%" xlink:href="https://www.wildtextures.com/wp-content/uploads/wildtextures-grey-felt-texture.jpg"/>
</svg>
它不起作用。有人可以帮我找出原因吗? 我设置了一个codepen,如果这对任何人有帮助的话。
编辑: 虽然答案有效,但既然我已经实现了它,我想警告其他所有人:在 Firefox 上,这会减慢我的 Three.js 场景的爬行速度(不过,我测试的所有其他浏览器似乎都很好)。
【问题讨论】:
-
对不起,我措辞错误,我的意思是“背景模糊()”。不过,CanIuse.com 向我证实了这一点。不幸的是我不能使用 blur(),因为我不能直接定位到 three.js 画布。
标签: svg svg-filters