JavaScript获取设备颜色深度|Screen colorDepth 属性

Screen 对象参考手册


定义与用法

colorDepth 属性返回目标设备或缓冲器上的调色板的比特深度。


语法格式

screen.colorDepth


示例代码

返回调色板的位深度:

<script>
    document.write("颜色深度: " + screen.colorDepth); 
</script>

以上实例输出结果:

亲自试试


浏览器支持

属性Google ChromeInternet ExplorerFirefoxSafariOpera
colorDepthYesYesYesYesYes

所有主要浏览器都支持 colorDepth 属性


更多示例

在8比特屏显示交替的背景颜色:

if (screen.colorDepth<=8)
    //为8位屏幕的简单的蓝色背景色
    document.body.style.background="#0000FF"
else
    //为现代屏幕的华丽的蓝色背景色
    document.body.style.background="#87CEFA"

亲自试试


本例包含了所有screen属性


Screen 对象参考手册


相关