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