CSSImageValue

Limited availability

This feature is not Baseline because it does not work in some of the most widely-used browsers.

CSS 类型对象模型 APICSSImageValue 接口表示取用图像的属性(例如 background-imagelist-style-imageborder-image-source)的值。

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

CSSStyleValue CSSImageValue

实例属性

无。

实例方法

继承 CSSStyleValue 的方法。

示例

创建元素

html
<button>魔杖</button>

我们添加了一些 CSS,包括请求二进制文件的背景图片:

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

我们获取元素的样式映射。然后,我们从样式映射中获取(get())背景图片(background-image),并将其字符串化:

js
// 获得元素
const button = document.querySelector("button");

// 使用 computedStyleMap() 读取所有已计算的样式
const allComputedStyles = button.computedStyleMap();

// 返回 CSSImageValue 示例
console.log(allComputedStyles.get("background-image"));
console.log(allComputedStyles.get("background-image").toString());

规范

Specification
CSS Typed OM Level 1
# imagevalue-objects

浏览器兼容性

参见