CSSFunctionDescriptors
Khả dụng hạn chế
This feature is not Baseline because it does not work in some of the most widely-used browsers.
Experimental: This is an experimental technology
Check the Browser compatibility table carefully before using this in production.
Giao diện CSSFunctionDescriptors của CSS Object Model đại diện cho các descriptor có trong một tập hợp khai báo CSS được biểu diễn bởi đối tượng CSSFunctionDeclarations.
Đối tượng CSSFunctionDescriptors được truy cập qua thuộc tính CSSFunctionDeclarations.style.
Thuộc tính phiên bản
Giao diện này cũng kế thừa các thuộc tính từ CSSStyleDeclaration.
CSSFunctionDescriptors.resultRead only Thử nghiệm-
Trả về một chuỗi đại diện cho descriptor
result, nếu có trong tập hợp khai báo liên quan.
Ví dụ
>Sử dụng cơ bản CSSFunctionDescriptors
Trong ví dụ này, chúng ta định nghĩa một hàm CSS tùy chỉnh và sau đó truy cập các khai báo của nó bằng CSSOM.
CSS
css
@function --lighter(--color <color>, --lightness-adjust <number>: 0.2) returns
<color> {
result: oklch(from var(--color) calc(l + var(--lightness-adjust)) c h);
}
JavaScript
js
// Get a CSSFunctionRule
const cssFunc = document.getElementById("css-output").sheet.cssRules[0];
// Accessing CSSFunctionDeclarations and CSSFunctionDescriptors
console.log(cssFunc.cssRules[0]); // CSSFunctionDeclarations
console.log(cssFunc.cssRules[0].style); // CSSFunctionDescriptors
console.log(cssFunc.cssRules[0].style.result);
Thông số kỹ thuật
| Thông số kỹ thuật |
|---|
| CSS Functions and Mixins Module> # cssfunctiondescriptors> |