这是 实验性技术
检查 浏览器兼容性表格 要小心谨慎在生产中使用这之前。

orientation 只读特性在 Screen interface returns the current orientation of the screen.

句法

var orientation = window.screen.orientation;
					

返回值

实例化的 ScreenOrientation representing the orientation of the screen.

Note that older, prefixed versions returned a DOMString 相当于 ScreenOrientation.type .

范例

var orientation = (screen.orientation || {}).type || screen.mozOrientation || screen.msOrientation;
if (orientation === "landscape-primary") {
  console.log("That looks good.");
} else if (orientation === "landscape-secondary") {
  console.log("Mmmh... the screen is upside down!");
} else if (orientation === "portrait-secondary" || orientation === "portrait-primary") {
  console.log("Mmmh... you should rotate your device to landscape");
} else if (orientation === undefined) {
  console.log("The orientation API isn't supported in this browser :(");
}
					

规范

规范 状态 注释
Screen Orientation API
The definition of 'orientation' in that specification.
工作草案 初始定义

浏览器兼容性

更新 GitHub 上的兼容性数据
桌面 移动
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet
orientation Chrome 38 Edge 12 Prefixed
12 Prefixed
Prefixed Implemented with the vendor prefix: ms
Edge does not return an 取向 object; instead, it returns the orientation type as a string.
Firefox Yes
Yes
Yes Prefixed
Prefixed Implemented with the vendor prefix: moz
IE 11 Prefixed
11 Prefixed
Prefixed Implemented with the vendor prefix: ms
Not supported on Windows 7.
Opera 25 Safari No WebView Android No Chrome Android 39 Firefox Android Yes
Yes
Yes Prefixed
Prefixed Implemented with the vendor prefix: moz
Opera Android No Safari iOS No Samsung Internet Android 4.0

图例

完整支持

完整支持

不支持

不支持

见实现注意事项。

要求使用供应商前缀或不同名称。

要求使用供应商前缀或不同名称。

另请参阅

元数据

  • 最后修改:
  1. Screen
  2. 特性
    1. availHeight
    2. availLeft
    3. availTop
    4. availWidth
    5. colorDepth
    6. height
    7. left
    8. mozBrightness
    9. mozEnabled
    10. onorientationchange
    11. orientation
    12. pixelDepth
    13. top
    14. width
  3. 方法
    1. lockOrientation()
    2. unlockOrientation()
  4. 继承:
    1. EventTarget
  5. Related pages for Screen Orientation API
    1. Screen.orientation
    2. ScreenOrientation

版权所有  © 2014-2026 乐数软件    

工业和信息化部: 粤ICP备14079481号-1