patternUnits
示例
html
<svg viewBox="0 0 200 100" xmlns="http://www.w3.org/2000/svg">
<!-- All geometry properties are relative to the current user space -->
<pattern
id="p1"
x="12.5"
y="12.5"
width="25"
height="25"
patternUnits="userSpaceOnUse">
<circle cx="10" cy="10" r="10" />
</pattern>
<!-- All geometry properties are relative to the target bounding box -->
<pattern
id="p2"
x=".125"
y=".125"
width=".25"
height=".25"
patternUnits="objectBoundingBox">
<circle cx="10" cy="10" r="10" />
</pattern>
<!-- Left square with user space tiles -->
<rect x="10" y="10" width="80" height="80" fill="url(#p1)" />
<!-- Right square with bounding box tiles -->
<rect x="110" y="10" width="80" height="80" fill="url(#p2)" />
</svg>
pattern
對於 <pattern>,patternUnits 定義用於元素的幾何屬性(x、y、width 和 height)的座標系。
| 值 | userSpaceOnUse | objectBoundingBox |
|---|---|
| 預設值 | objectBoundingBox |
| 可動畫 | 是 |
userSpaceOnUse-
此值表示幾何屬性的所有座標都引用使用者座標系,該座標系是在應用模式時定義的。
objectBoundingBox-
此值表示幾何屬性的所有座標都表示應用模式的元素的邊界框的分數或百分比。邊界框可以被認為與
<pattern>的內容繫結到 "0 0 1 1"viewBox相同。
規範
| 規範 |
|---|
| 可縮放向量圖形 (SVG) 2 # PatternElementPatternUnitsAttribute |
瀏覽器相容性
BCD 表格僅在啟用 JavaScript 的瀏覽器中載入。