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 |
浏览器兼容性
加载中…