SVGPreserveAspectRatio:meetOrSlice 属性

Baseline 已广泛支持

此特性已相当成熟,可在许多设备和浏览器版本上使用。自 ⁨2015 年 7 月⁩以来,各浏览器均已提供此特性。

meetOrSliceSVGPreserveAspectRatio 接口的一个只读属性,它反映了该接口中 SVG_MEETORSLICE_* 常量所指定的 meet-or-slice 值的类型。

以下之一:

  • SVGPreserveAspectRatio.SVG_MEETORSLICE_UNKNOWN (0)
  • SVGPreserveAspectRatio.SVG_MEETORSLICE_MEET (1)
  • SVGPreserveAspectRatio.SVG_MEETORSLICE_SLICE (2)

示例

访问 meetOrSlice 属性

html
<svg
  xmlns="http://www.w3.org/2000/svg"
  width="400"
  height="200"
  preserveAspectRatio="xMidYMid slice">
  <circle cx="100" cy="100" r="50" fill="blue" />
</svg>
js
const svgElement = document.querySelector("svg");

// Access the meetOrSlice property
console.log(svgElement.preserveAspectRatio.baseVal.meetOrSlice); // Output: 2 (SVG_MEETORSLICE_SLICE)

规范

规范
Scalable Vector Graphics (SVG) 2
# __svg__SVGPreserveAspectRatio__meetOrSlice

浏览器兼容性