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

浏览器兼容性

Report problems with this compatibility data on GitHub
desktopmobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
pixelDepth

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support
See implementation notes.

参见