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

浏览器兼容性

另见