ウィンドウscreen.width
例
画面の全幅を取得します。
let width = screen.width;
以下の「自分で試してみてください」の例をもっと見てください。
定義と使用法
このwidth
プロパティは、ユーザーの画面の全幅を返します。
プロパティは、width
幅をピクセル単位で返します。
width
プロパティは読み取り専用です。
ノート
heightプロパティを使用して 、ユーザーの画面の全高を取得します。
構文
screen.width
戻り値
タイプ | 説明 |
数 | ユーザーの画面の全幅(ピクセル単位)。 |
その他の例
すべての画面プロパティ:
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.width
すべてのブラウザでサポートされています:
Chrome | IE | Edge | Firefox | Safari | Opera |
Yes | Yes | Yes | Yes | Yes | Yes |