Screen: orientation 属性
Screen 接口的只读属性 orientation 返回屏幕的当前方向。
值
一个 ScreenOrientation 实例,表示屏幕的方向。
请注意,较旧的、带有前缀的版本返回一个字符串,该字符串等同于 ScreenOrientation.type。
示例
js
switch (screen.orientation.type) {
case "landscape-primary":
console.log("That looks good.");
break;
case "landscape-secondary":
console.log("Mmm… the screen is upside down!");
break;
case "portrait-secondary":
case "portrait-primary":
console.log("Mmm… you should rotate your device to landscape");
break;
default:
console.log("The orientation API isn't supported in this browser :(");
}
规范
| 规范 |
|---|
| 屏幕方向 # dom-screen-orientation |
浏览器兼容性
加载中…