Window screen.availWidth
实例
获取屏幕的可用宽度:
<!DOCTYPE html><html><body><h2>availWidth 属性</h2><p id="demo"><script>let width = screen.availWidth;document.getElementById("demo").innerHTML = width + "px";</script></body></html>
定义与用法
availWidth 属性返回用户屏幕的宽度。
availWidth 属性返回以像素为单位的宽度。
availWidth 属性返回宽度减去了界面功能,如 Windows 任务栏。availWidth 属性是只读的。
备注
要获得屏幕的高度,请使用 availHeight 属性。
语法
screen.availWidth
返回值
| 类型 | 描述 |
| 一个数字 | 用户屏幕的高度,以像素为单位 |
更多实例
所有 screen 属性:
<!DOCTYPE html><html><body><h2>Screen 属性</h2><div id="demo"></div><script>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;document.getElementById("demo").innerHTML = text;</script></body></html>
浏览器支持
screen.availWidth 所有浏览器都支持:
| 属性 | |||||
|---|---|---|---|---|---|
| screen.availWidth | Yes | Yes | Yes | Yes | Yes |
相关页面
screen.width 属性