CSSImageValue
Limited availability
This feature is not Baseline because it does not work in some of the most widely-used browsers.
Giao diện CSSImageValue của CSS Typed Object Model API đại diện cho các giá trị của các thuộc tính nhận ảnh, ví dụ background-image, list-style-image hoặc border-image-source.
Đối tượng CSSImageValue đại diện cho <image> liên quan đến URL, chẳng hạn như url() hoặc <image()>, nhưng không phải linear-gradient() hoặc element().
Thuộc tính phiên bản
Không có.
Phương thức phiên bản
Kế thừa các phương thức từ CSSStyleValue.
Ví dụ
Chúng ta tạo một phần tử:
html
<button>Magic Wand</button>
Chúng ta thêm một số CSS, bao gồm ảnh nền yêu cầu tệp nhị phân:
css
button {
display: inline-block;
min-height: 100px;
min-width: 100px;
background: no-repeat 5% center url("magic-wand.png") aqua;
}
Chúng ta lấy style map của phần tử. Sau đó chúng ta get() background-image từ style map và stringify nó:
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());
Thông số kỹ thuật
| Specification |
|---|
| CSS Typed OM Level 1> # imagevalue-objects> |