CSSImageValue
CSSImageValue 接口属于 CSS Typed Object Model API,它表示接受图像的属性值,例如 background-image、list-style-image 或 border-image-source。
CSSImageValue 对象表示涉及 URL 的 <image>,例如 url() 或 image(),但不包括 linear-gradient() 或 element()。
实例属性
无。
实例方法
继承自 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 |
浏览器兼容性
加载中…