Screen

Baseline Widely available *

This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.

* Some parts of this feature may have varying levels of support.

Screen 接口表示一个屏幕窗口,往往指的是当前正在被渲染的 window 对象,可以使用 window.screen 获取它。

请注意:由浏览器决定提供屏幕对象,此对象一般通过当前浏览器窗口活动状态动态检测来得到。

属性

Screen.availTop

Specifies the y-coordinate of the first pixel that is not allocated to permanent or semipermanent user interface features.

Screen.availLeft

返回屏幕左边边界的第一个像素点

Screen.availHeight

Specifies the height of the screen, in pixels, minus permanent or semipermanent user interface features displayed by the operating system, such as the Taskbar on Windows.

Screen.availWidth

返回窗口中水平方向可用空间的像素值。

Screen.colorDepth

返回屏幕的色彩深度。

Screen.height

以像素为单位返回屏幕的高度。

Screen.left

返回从最左边界到当前屏幕的像素值。

Screen.orientation

返回当前屏幕的转向。

Screen.pixelDepth

获取屏幕的像素点

Screen.top

返回最上边界到当前屏幕的像素值。

Screen.width

返回屏幕的宽度。

Screen.mozEnabled

布尔值。如果设置为 false 将关闭设备的屏幕。

Screen.mozBrightness

控制设备屏幕的亮度。期望参数是 0-1.0 之间的浮点数。

Events handler

Screen.onorientationchange

orientationchange 事件的时间处理器。

方法

方法继承自其父接口 EventTarget

Screen.lockOrientation 已弃用

锁定屏幕转向(仅在全屏或者已安装的 APP 中生效)

Screen.unlockOrientation 已弃用

解锁屏幕转向(仅在全屏或者已安装的 APP 中生效)

示例

js
if (screen.pixelDepth < 8) {
  // use low-color version of page
} else {
  // use regular, colorful page
}

规范

Specification
CSSOM View Module
# the-screen-interface

浏览器兼容性

Report problems with this compatibility data on GitHub
desktopmobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
Screen
availHeight
availLeft
Non-standard
Relative to the Multi-screen origin
Non-standard
availTop
Non-standard
Relative to the Multi-screen origin
Non-standard
availWidth
change event
Experimental
colorDepth
height
isExtended
Experimental
left
Non-standard
Relative to the Multi-screen origin
Non-standard
lockOrientation
Deprecated
mozBrightness
DeprecatedNon-standard
mozEnabled
DeprecatedNon-standard
orientation
orientationchange event
DeprecatedNon-standard
pixelDepth
top
DeprecatedNon-standard
Relative to the Multi-screen origin
DeprecatedNon-standard
unlockOrientation
Deprecated
width

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support
Partial support
Partial support
No support
No support
Experimental. Expect behavior to change in the future.
Non-standard. Check cross-browser support before using.
Deprecated. Not for use in new websites.
See implementation notes.
User must explicitly enable this feature.
Requires a vendor prefix or different name for use.
Has more compatibility info.