CSSMathValue: operator property

Limited availability

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

Thuộc tính chỉ đọc CSSMathValue.operator của giao diện CSSMathValue chỉ ra toán tử mà kiểu con hiện tại đại diện. Ví dụ, nếu kiểu con CSSMathValue hiện tại là CSSMathSum, thuộc tính này sẽ trả về chuỗi "sum".

Giá trị

Một String.

Giao diện Giá trị
CSSMathSum "sum"
CSSMathProduct "product"
CSSMathMin "min"
CSSMathMax "max"
CSSMathClamp "clamp"
CSSMathNegate "negate"
CSSMathInvert "invert"

Ví dụ

Chúng ta tạo một phần tử với width được xác định bằng hàm calc(), sau đó dùng console.log() để ghi operator.

html
<div>My width has a <code>calc()</code> function</div>

Chúng ta gán width với phép tính

css
div {
  width: calc(50% - 0.5vw);
}

Chúng ta thêm JavaScript

js
const styleMap = document.querySelector("div").computedStyleMap();

console.log(styleMap.get("width")); // CSSMathSum {values: CSSNumericArray, operator: "sum"}
console.log(styleMap.get("width").values); // CSSNumericArray {0: CSSUnitValue, 1: CSSMathNegate, length: 2}
console.log(styleMap.get("width").operator); // 'sum'
console.log(styleMap.get("width").values[1].operator); // 'negate'

CSSMathValue.operator trả về sum cho biểu thức và negate cho toán tử trên giá trị thứ hai.

Thông số kỹ thuật

Specification
CSS Typed OM Level 1
# dom-cssmathvalue-operator

Tương thích trình duyệt