SVGPatternElement: patternContentUnits 属性
SVGPatternElement
接口的只读属性 patternContentUnits
反映了给定 <pattern>
元素的 patternContentUnits
属性。它指定了图案内容的坐标系统,并取自 SVGUnitTypes
中定义的其中一个常量。
值
一个 SVGAnimatedEnumeration
对象。
示例
给定以下 SVG
html
<svg viewBox="0 0 200 200" xmlns="http://www.w3.org/2000/svg">
<defs>
<pattern
id="pattern1"
width="10"
height="10"
patternContentUnits="userSpaceOnUse">
<circle cx="5" cy="5" r="5" fill="blue" />
</pattern>
<pattern
id="pattern2"
width="10"
height="10"
patternContentUnits="objectBoundingBox">
<circle cx="5" cy="5" r="5" fill="red" />
</pattern>
</defs>
<rect x="0" y="0" width="100" height="100" fill="url(#pattern1)" />
<rect x="100" y="0" width="100" height="100" fill="url(#pattern2)" />
</svg>
我们可以访问 patternContentUnits
属性
js
const patterns = document.querySelectorAll("pattern");
console.log(patterns[0].patternContentUnits.baseVal); // output: 1 (SVGUnitTypes.USERSPACEONUSE)
console.log(patterns[1].patternContentUnits.baseVal); // output: 2 (SVGUnitTypes.OBJECTBOUNDINGBOX)
规范
规范 |
---|
Scalable Vector Graphics (SVG) 2 # __svg__SVGPatternElement__patternContentUnits |
浏览器兼容性
加载中…