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 |
瀏覽器相容性
載入中…