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>元素。