maskUnits
示例
html
<svg viewBox="0 0 100 100" xmlns="http://www.w3.org/2000/svg">
<mask
id="myMask1"
maskUnits="userSpaceOnUse"
x="20%"
y="20%"
width="60%"
height="60%">
<rect fill="black" x="0" y="0" width="100%" height="100%" />
<circle fill="white" cx="50" cy="50" r="35" />
</mask>
<mask
id="myMask2"
maskUnits="objectBoundingBox"
x="20%"
y="20%"
width="60%"
height="60%">
<rect fill="black" x="0" y="0" width="100%" height="100%" />
<circle fill="white" cx="50" cy="50" r="35" />
</mask>
<!-- Some reference rect to materialized the mask -->
<rect id="r1" x="0" y="0" width="45" height="45" />
<rect id="r2" x="0" y="55" width="45" height="45" />
<rect id="r3" x="55" y="55" width="45" height="45" />
<rect id="r4" x="55" y="0" width="45" height="45" />
<!-- The first 3 rect are masked with useSpaceOnUse units -->
<use mask="url(#myMask1)" href="#r1" fill="red" />
<use mask="url(#myMask1)" href="#r2" fill="red" />
<use mask="url(#myMask1)" href="#r3" fill="red" />
<!-- The last rect is masked with objectBoundingBox units -->
<use mask="url(#myMask2)" href="#r4" fill="red" />
</svg>
mask
對於 <mask>,maskUnits 定義了用於該元素幾何屬性(x、y、width 和 height)的座標系。
| 值 | userSpaceOnUse | objectBoundingBox |
|---|---|
| 預設值 | objectBoundingBox |
| 可動畫 | 是 |
userSpaceOnUse-
此值表示幾何屬性的所有座標都引用使用者座標系,該座標系在建立蒙版時定義。
objectBoundingBox-
此值表示幾何屬性的所有座標都表示應用蒙版的元素的邊界框的分數或百分比。邊界框可以認為與
<mask>內容繫結到 "0 0 1 1"viewBox相同。
規範
| 規範 |
|---|
| CSS 蒙版模組級別 1 # element-attrdef-mask-maskunits |
瀏覽器相容性
BCD 表格僅在啟用 JavaScript 的瀏覽器中載入。