此页面由社区从英文翻译而来。了解更多并加入 MDN Web Docs 社区。

View in English Always switch to English

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 ⁨2015年7月⁩.

返回屏幕的位深度/色彩深度(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

浏览器兼容性

参见