CSSImageValue

可用性有限

此特性不是基線特性,因為它在一些最廣泛使用的瀏覽器中不起作用。

CSSImageValue 介面屬於 CSS Typed Object Model API,它表示接受影像的屬性值,例如 background-imagelist-style-imageborder-image-source

CSSImageValue 物件表示涉及 URL 的 <image>,例如 url()image(),但不包括 linear-gradient()element()

CSSStyleValue CSSImageValue

例項屬性

無。

例項方法

繼承自 CSSStyleValue 的方法。

示例

我們建立一個元素

html
<button>Magic Wand</button>

我們新增一些 CSS,包括一個請求二進位制檔案的背景影像

css
button {
  display: inline-block;
  min-height: 100px;
  min-width: 100px;
  background: no-repeat 5% center url("magic-wand.png") aqua;
}

我們獲取元素的樣式對映。然後我們從樣式對映中獲取 background-image 並將其字串化

js
// get the element
const button = document.querySelector("button");

// Retrieve all computed styles with computedStyleMap()
const allComputedStyles = button.computedStyleMap();

// Return the CSSImageValue Example
console.log(allComputedStyles.get("background-image"));
console.log(allComputedStyles.get("background-image").toString());

規範

規範
CSS 型別化 OM Level 1
# imagevalue-objects

瀏覽器相容性

另見