Screen colorDepth property
Definition and Usage
colorDepth property returns the bit depth of the target device or a palette on the buffer.
grammar
screen.colorDepth
Browser Support
All major browsers support colorDepth property
Examples s
Example 1
Returns the bit depth color palette:
<script>
document.write("颜色深度: " + screen.colorDepth);
</script>
document.write("颜色深度: " + screen.colorDepth);
</script>
Examples of the above output:
try it"
Example 2
In the 8-bit screen display alternating background colors:
if (screen.colorDepth <= 8)
// 8-bit screen simple blue background color
document.body.style.background = "# 0000FF"
else
// Background color is gorgeous blue modern screen
document.body.style.background = "# 87CEFA"
// 8-bit screen simple blue background color
document.body.style.background = "# 0000FF"
else
// Background color is gorgeous blue modern screen
document.body.style.background = "# 87CEFA"
try it"
More examples
This example contains all screen attributes
Screen objects