Screen 对象基础教程文档
收录于 2023-04-20 00:10:05 · بالعربية · English · Español · हिंदीName · 日本語 · Русский язык · 中文繁體
JavaScript screen对象保存浏览器屏幕的信息。可用于显示屏幕的width,height,colorDepth,pixelDepth等。
导航器对象是window属性,因此可以通过以下方式访问:
window.screen
或者,
screen
JavaScript屏幕对象的属性
屏幕对象有许多属性,可返回浏览器的信息。
属性 | 说明 |
width | 返回屏幕宽度 |
height | 返回屏幕的高度 |
availWidth | 返回可用宽度 |
availHeight | 返回可用高度 |
colorDepth | 返回颜色深度 |
pixelDepth | 返回像素深度。 |
JavaScript屏幕对象的示例
让我们看看屏幕对象的不同用法。
<script>
document.writeln("<br/>screen.width: "+screen.width);
document.writeln("<br/>screen.height: "+screen.height);
document.writeln("<br/>screen.availWidth: "+screen.availWidth);
document.writeln("<br/>screen.availHeight: "+screen.availHeight);
document.writeln("<br/>screen.colorDepth: "+screen.colorDepth);
document.writeln("<br/>screen.pixelDepth: "+screen.pixelDepth);
</script>
document.writeln("<br/>screen.width: "+screen.width);
document.writeln("<br/>screen.height: "+screen.height);
document.writeln("<br/>screen.availWidth: "+screen.availWidth);
document.writeln("<br/>screen.availHeight: "+screen.availHeight);
document.writeln("<br/>screen.colorDepth: "+screen.colorDepth);
document.writeln("<br/>screen.pixelDepth: "+screen.pixelDepth);
</script>
screen.width:1366
screen.height:768
screen.availwidth:1366
screen.availHeight:728
screen.colorDepth:24
screen.pixelDepth:24
screen.height:768
screen.availwidth:1366
screen.availHeight:728
screen.colorDepth:24
screen.pixelDepth:24