SVGFEDropShadowElement: setStdDeviation() 方法
SVGFEDropShadowElement
接口的 setStdDeviation()
方法用于设置 stdDeviation
属性的值。
语法
js
setStdDeviation(x, y)
参数
x
-
一个表示
stdDeviation
属性 X 分量的浮点数。 y
-
一个表示
stdDeviation
属性 Y 分量的浮点数。
返回值
无(undefined
)。
示例
使用 setStdDeviation()
在此示例中,我们使用 SVGFEDropShadowElement
接口的 setStdDeviation()
方法来设置 <feDropShadow>
滤镜阴影效果的模糊操作的水平和垂直标准差。
html
<svg height="200" width="200" viewBox="0 0 200 200">
<defs>
<filter id="drop-shadow-filter">
<feDropShadow
in="SourceGraphic"
dx="10"
dy="10"
stdDeviation="5 5"
flood-color="gray" />
</filter>
</defs>
<!-- Rectangle with an initial gray shadow -->
<rect
x="50"
y="50"
width="100"
height="100"
fill="red"
filter="url(#drop-shadow-filter)" />
</svg>
<!-- Button to update the shadow -->
<button id="updateShadow" type="button">Update Shadow</button>
js
// Get the feDropShadow element
const dropShadow = document.querySelector("feDropShadow");
// Button to trigger the update
document.getElementById("updateShadow").addEventListener("click", () => {
// Change the standard deviation (blur radius) of the shadow
dropShadow.setStdDeviation(15, 20);
});
点击红色矩形可更新阴影效果的模糊效果。
规范
规范 |
---|
滤镜效果模块第 1 级 # dom-svgfedropshadowelement-setstddeviation |
浏览器兼容性
加载中…