Window screen.pixelDepth 属性
实例
获取屏幕的颜色分辨率:
<!DOCTYPE html><html><body><h2>pixelDepth 属性</h2><p id="demo"><script>let depth = screen.pixelDepth;document.getElementById("demo").innerHTML = depth + " bits per pixel";</script></body></html>
定义与用法
pixelDepth 属性返回屏幕的颜色深度。
pixelDepth 属性返回颜色深度,单位为位/像素。
pixelDepth 属性是只读的。
也可以参考:
备注
Internet Explorer 9 及更早版本不支持 pixelDepth 属性。
但是,pixelDepth 和 colorDepth 返回相同的值。
由于所有浏览器都支持 colorDepth,因此请改用该属性。
语法
screen.pixelDepth
返回值
| Type | 描述 |
| 一个数字 | 颜色分辨率(单位:位/像素): 1, 4, 8, 15, 16, 24, 32, or 48。 |
更多实例
所有 screen 属性:
<!DOCTYPE html><html><body><h2>Screen 属性</h2><div id="demo"></div><script>let text = "Total width/height: " + screen.width + "*" + screen.height + "<br>" +"Available width/height: " + screen.availWidth + "*" + screen.availHeight + "<br>" +"Color depth: " + screen.colorDepth + "<br>" +"Color resolution: " + screen.pixelDepth;document.getElementById("demo").innerHTML = text;</script></body></html>
浏览器支持
screen.pixelDepth 所有浏览器都支持:
| 属性 | |||||
|---|---|---|---|---|---|
| screen.pixelDepth | Yes | Yes | Yes | Yes | Yes |
相关页面
screen.width 属性