图案单位
patternUnits 属性指示用于 <pattern> 元素的几何属性的坐标系。
你可以将此属性与以下 SVG 元素一起使用
示例
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>
元素
你可以在下面部分描述的 SVG 元素中使用此属性。
<pattern>
对于 <pattern>,patternUnits 定义了元素几何属性(x、y、width 和 height)所使用的坐标系。
| 值 | userSpaceOnUse | objectBoundingBox |
|---|---|
| 默认值 | objectBoundingBox |
| 可动画的 | 是 |
userSpaceOnUse-
此值表示几何属性的所有坐标均指图案应用时定义的用户坐标系。
objectBoundingBox-
此值表示几何属性的所有坐标均表示应用图案的元素的边界框的分数或百分比。边界框可被视为与将
<pattern>的内容绑定到"0 0 1 1"viewBox时相同。
规范
| 规范 |
|---|
| Scalable Vector Graphics (SVG) 2 # PatternElementPatternUnitsAttribute |
浏览器兼容性
加载中…