SVGFEImageElement: preserveAspectRatio 屬性

Baseline 已廣泛支援

此特性已相當成熟,可在許多裝置和瀏覽器版本上使用。自 ⁨2015 年 7 月⁩以來,各瀏覽器均已提供此特性。

SVGFEImageElement 介面的只讀屬性 preserveAspectRatio 反映了給定 <feImage> 元素的 preserveAspectRatio 屬性。

一個 SVGAnimatedPreserveAspectRatio 物件。

示例

訪問 preserveAspectRatio 屬性

html
<svg xmlns="http://www.w3.org/2000/svg" width="400" height="200">
  <defs>
    <filter id="image-filter">
      <!-- feImage element with preserveAspectRatio attribute -->
      <feImage
        href="https://via.placeholder.com/150"
        x="0"
        y="0"
        width="150"
        height="150"
        preserveAspectRatio="xMidYMid meet" />
    </filter>
  </defs>

  <!-- Rectangle with the filter applied -->
  <rect
    x="50"
    y="50"
    width="200"
    height="100"
    fill="blue"
    filter="url(#image-filter)" />
</svg>
js
// Select the feImage element
const feImageElement = document.querySelector("feImage");

// Access the preserveAspectRatio property
console.dir(feImageElement.preserveAspectRatio); // Output: SVGAnimatedPreserveAspectRatio object

規範

規範
濾鏡效果模組第 1 級
# dom-svgfeimageelement-preserveaspectratio

瀏覽器相容性

另見