SVGViewElement: preserveAspectRatio 属性
SVGViewElement
接口的只读属性 preserveAspectRatio
反映了给定 <view>
元素的 preserveAspectRatio
属性。它定义了 view
中的内容在保留其宽高比的情况下,应如何缩放到适应其视口。
值
示例
给定以下 SVG,我们可以使用 preserveAspectRatio
属性来检索 view
元素的缩放行为。
html
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 200 200">
<view id="view1" preserveAspectRatio="xMidYMid meet"></view>
<circle cx="100" cy="100" r="80" fill="blue" />
</svg>
我们可以访问 preserveAspectRatio
属性。
js
const view = document.querySelector("view");
console.log(view.preserveAspectRatio.baseVal); // output: SVGPreserveAspectRatio {align: 1, meetOrSlice: 1}
规范
规范 |
---|
Scalable Vector Graphics (SVG) 2 # __svg__SVGFitToViewBox__preserveAspectRatio |
浏览器兼容性
加载中…