SVGElement: viewportElement 属性
SVGElement
接口的 viewportElement
属性表示建立了当前视口(viewport)的 SVGElement
。通常是最近的祖先 <svg>
元素。如果给定的元素是最外层的 <svg>
元素,则为 null
。
值
一个 SVGElement
。
示例
检索 viewportElement
html
<svg id="outerSvg" width="200" height="200" xmlns="http://www.w3.org/2000/svg">
<svg id="innerSvg" x="10" y="10" width="100" height="100">
<circle id="circle" cx="50" cy="50" r="40" fill="blue"></circle>
</svg>
</svg>
js
const circle = document.getElementById("circle");
const innerSvg = document.getElementById("innerSvg");
const outerSvg = document.getElementById("outerSvg");
console.log(circle.viewportElement); // Output: <svg id="innerSvg">...</svg>
console.log(innerSvg.viewportElement); // Output: <svg id="outerSvg">...</svg>
console.log(outerSvg.viewportElement); // Output: null
规范
规范 |
---|
Scalable Vector Graphics (SVG) 2 # __svg__SVGElement__viewportElement |
浏览器兼容性
加载中…
另见
SVGElement.ownerSVGElement
:检索当前 SVG 元素的最近祖先<svg>
元素。