这是
实验性技术
检查
浏览器兼容性表格
要小心谨慎在生产中使用这之前。
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. |
工作草案 | 初始定义 |
| 桌面 | 移动 | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
orientation
|
Chrome 38 |
Edge
12
Prefixed
|
Firefox
Yes
|
IE
11
Prefixed
|
Opera 25 | Safari No | WebView Android No | Chrome Android 39 |
Firefox Android
Yes
|
Opera Android No | Safari iOS No | Samsung Internet Android 4.0 |
完整支持
不支持
见实现注意事项。
要求使用供应商前缀或不同名称。
Screen