SVGSVGElement: preserveAspectRatio 屬性
SVGSVGElement 介面的只讀屬性 preserveAspectRatio 反映了給定元素的 preserveAspectRatio 屬性。它定義了 SVG 元素的 **內容** 如何縮放以適應給定空間,同時保持其縱橫比。
值
示例
給定以下 SVG,我們可以使用 preserveAspectRatio 屬性來檢索 SVG 元素的縮放行為。
html
<svg
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 200 200"
preserveAspectRatio="xMidYMid meet">
<circle cx="100" cy="100" r="50" fill="blue" />
</svg>
我們可以訪問 preserveAspectRatio 屬性。
js
const svgElement = document.querySelector("svg");
console.log(svgElement.preserveAspectRatio.baseVal); // output: SVGPreserveAspectRatio {align: 1, meetOrSlice: 1}
規範
| 規範 |
|---|
| Scalable Vector Graphics (SVG) 2 # __svg__SVGFitToViewBox__preserveAspectRatio |
瀏覽器相容性
載入中…