圖案內容單位
patternContentUnits 屬性指示要用於 <pattern> 元素內容的座標系。
注意:如果 <pattern> 元素上指定了 viewBox 屬性,則此屬性無效。
你可以將此屬性與以下 SVG 元素一起使用
示例
html
<svg viewBox="0 0 200 100" xmlns="http://www.w3.org/2000/svg">
<!--
A pattern tile that content coordinates and values are
computed against the current coordinate user space.
Note that the size of the tile is computed against
the bounding box of the target element
-->
<pattern
id="p1"
width="20%"
height="20%"
patternContentUnits="userSpaceOnUse">
<circle cx="10" cy="10" r="10" />
</pattern>
<!--
A pattern tile that content coordinates and values are
computed against the bounding box of the target element.
Note that the size of the tile is also computed against
the bounding box of the target element
-->
<pattern
id="p2"
width="20%"
height="20%"
patternContentUnits="objectBoundingBox">
<circle cx=".1" cy=".1" r=".1" />
</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>
元素
你可以在下面部分描述的 SVG 元素中使用此屬性。
<pattern>
對於 <pattern>,patternContentUnits 定義了元素內容所使用的座標系。
| 值 | userSpaceOnUse | objectBoundingBox |
|---|---|
| 預設值 | userSpaceOnUse |
| 可動畫的 | 是 |
userSpaceOnUse-
此值表示
<pattern>元素內的所有座標都引用在建立圖案瓦片時定義的the user coordinate system(使用者座標系)。 objectBoundingBox-
此值表示
<pattern>元素內的所有座標都相對於應用該圖案的元素的 bounding box(邊界框)。邊界框可以被視為與圖案瓦片的寬度和高度均為 100% 時,內容具有"0 0 1 1"viewBox的情況相同。
規範
| 規範 |
|---|
| Scalable Vector Graphics (SVG) 2 # PatternElementPatternContentUnitsAttribute |
瀏覽器相容性
載入中…