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 |
瀏覽器相容性
載入中…