SYNCERのロゴ
アイキャッチ画像

Screen.width - 全体の横幅

widthは、Screenのプロパティです。ディスプレイ全体の横幅を返します。タスクバーやメニューバーなど、半永久的に固定されたスペースを含めた全体です。自由に使える領域の幅を知りたい場合は、availWidthを参照します。

概要

名前
width
所属
Screen
IDL
readonly attribute long width;
仕様書
https://drafts.csswg.org/cssom-view/#dom-screen-availwidth

説明

ディスプレイ全体の横幅をピクセル単位の数値で返す。

デモ

Screen.widthのデモです。

<!-- このコードは編集できます。 -->

<!DOCTYPE html>
<html>
<head>
<style>
body { word-break: break-all ; }
div#result { white-space: pre-wrap ; }
</style>
</head>
<body>
<div id="result"></div>
<script>
console.log( screen ) ;

appendText( "availWidth: " + screen.availWidth + "\n" ) ;
appendText( "availHeight: " + screen.availHeight + "\n" ) ;
appendText( "width: " + screen.width + "\n" ) ;
appendText( "height: " + screen.height + "\n" ) ;
appendText( "colorDepth: " + screen.colorDepth + "\n" ) ;
appendText( "pixelDepth: " + screen.pixelDepth + "\n" ) ;

function appendText ( text ) {
	document.getElementById( "result" ).appendChild( document.createTextNode( text ) ) ;
}
</script>

</body>
</html>

サポート状況

ChromeFirefoxSafariEdgeIEOperaiOS SafariAndroid
  • Twitterでシェア
  • Facebookでシェア
  • Google+でシェア
  • はてなブックマークでシェア
  • pocketに保存
  • LINEでシェア
更新履歴
2017年10月18日 (水)
コンテンツを公開しました。