ウィンドウscreen.colorDepth
例
カラーパレットのビット深度を取得します。
let depth = screen.colorDepth;
以下の「自分で試してみてください」の例をもっと見てください。
定義と使用法
プロパティは、画面のcolorDepth
色深度を返します。
colorDepth
プロパティは、ピクセルあたりのビット数で深度を返します。
colorDepth
プロパティは読み取り専用です。
構文
screen.colorDepth
戻り値
タイプ | 説明 |
数 | 画面のカラーパレットの深さ(ピクセルあたりのビット数):1、4、8、15、16、24、32 、または48。 |
その他の例
8ビット画面の代替背景色を表示します(最新の色をサポートしていない8ビット画面が代わりに醜い代替色を使用することを避けるため):
if (screen.colorDepth <= 8)
//simple blue background color for 8 bit screens
document.body.style.background = "#0000FF"
else
//fancy blue background color for modern screens
document.body.style.background = "#87CEFA"
すべての画面プロパティ:
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;
ブラウザのサポート
screen.colorDepth
すべてのブラウザでサポートされています:
Chrome | IE | Edge | Firefox | Safari | Opera |
Yes | Yes | Yes | Yes | Yes | Yes |