Screen.pixelDepth

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.

返回屏幕的位深度/色彩深度(bit depth)。根据 CSSOM( CSS 对象模型 ) 视图,为兼容起见,该值总为 24。

示例

js
// 如果没有足够的位深度/色彩深度(bit depth),就选择一个更纯的颜色
if (window.screen.pixelDepth > 8) {
  document.style.color = "#FAEBD7";
} else {
  document.style.color = "#FFFFFF";
}

规范

Specification
CSSOM View Module
# dom-screen-pixeldepth

浏览器兼容性

BCD tables only load in the browser

参见