From 33058f2b292b3a581333bdfb21b8f671898c5060 Mon Sep 17 00:00:00 2001 From: Peter Bengtsson Date: Tue, 8 Dec 2020 14:40:17 -0500 Subject: initial commit --- .../web/api/screen/lockorientation/index.html | 198 +++++++++++++++++++++ 1 file changed, 198 insertions(+) create mode 100644 files/zh-cn/web/api/screen/lockorientation/index.html (limited to 'files/zh-cn/web/api/screen/lockorientation') diff --git a/files/zh-cn/web/api/screen/lockorientation/index.html b/files/zh-cn/web/api/screen/lockorientation/index.html new file mode 100644 index 0000000000..f9169a396b --- /dev/null +++ b/files/zh-cn/web/api/screen/lockorientation/index.html @@ -0,0 +1,198 @@ +--- +title: Screen.lockOrientation() +slug: Web/API/Screen/lockOrientation +translation_of: Web/API/Screen/lockOrientation +--- +

{{APIRef("CSSOM View")}}{{SeeCompatTable}}

+ +

lockOrientation 此方法会把屏幕锁定为指定的方向.

+ +
+

注意: 此方法仅适用于已安装的Web apps 或 全屏模式 的Web 页面.

+
+ +

使用方法

+ +
lockedAllowed = window.screen.lockOrientation(orientation);
+ +

参数介绍

+ +
+
orientation
+
需要锁定屏幕的方向。这个参数是一个字符串或者是一个由字符串组成的数组。通过多个字符串可以让屏幕只在选定的方向上进行旋转。
+
+ +

以下的字符串即表示你也许会指定的一些可能的方向。

+ +
+
portrait-primary
+
它表示屏幕处于主要的肖像模式时的方向。如果设备处于正常位置且该位置处于纵向位置,或设备的正常位置处于横向并且设备保持顺时针转动90°,则会在主肖像模式下考虑屏幕。正常的位置是依赖于设备的。
+
portrait-secondary
+
+

它表示屏幕处于辅助肖像模式时的方向。如果设备与正常位置保持180°,并且该位置处于纵向位置,或者设备的正常位置处于横向位置,并且持有的设备逆时针转动90°,则屏幕将处于辅助人像模式。正常的位置是依赖于设备的。

+
+
landscape-primary
+
它代表了屏幕处于主要风景模式时的方向。 如果设备保持在正常位置,并且该位置处于横向位置,或者设备的正常位置处于纵向位置,并且所保持的设备顺时针旋转90°,则会将其视为主要横向模式。正常的位置是依赖于设备的。
+
landscape-secondary
+
它代表了屏幕处于次要风景模式时的方向。如果设备与其正常位置保持180°并且该位置处于横向,或者如果设备的正常位置是纵向的,并且所保持的设备逆时针旋转90°,则将其视为次要横向模式。正常的位置是依赖于设备的。
+
portrait
+
它表示同时包含 portrait-primary 和 portrait-secondary.
+
landscape
+
它表示同时包含 landscape-primary 和 landscape-secondary.
+
+ +
+
default
+
它代表 portrait-primary 和 landscape-primary 主要取决于设备的自然方向。例如,如果面板分辨率为1280 * 800,则 default 为横向,如果分辨率为800 * 1280,则 default 为纵向。
+
+ +
+

注意: 可同时设置多个锁定值。因此,如果锁定设置为只有一个方向,屏幕方向将永远不会改变,直到屏幕方向解锁。否则,只要方向在设备锁定的方向之中,屏幕方向就会从一个方向改变到另一个方向。

+
+ +

返回值

+ +

如果方向被授权锁定,则返回 true ;如果方向锁定被拒绝,则返回 false。请注意,返回值并不表示屏幕方向确实被锁定:可能会有延迟。

+ +

示例

+ +

使用 DOMString 参数

+ +
screen.lockOrientationUniversal = screen.lockOrientation || screen.mozLockOrientation || screen.msLockOrientation;
+
+if (screen.lockOrientationUniversal("landscape-primary")) {
+  // 方向已锁定成功
+} else {
+  // 方向锁定失败
+}
+
+ +

使用 Array 参数

+ +
screen.lockOrientationUniversal = screen.lockOrientation || screen.mozLockOrientation || screen.msLockOrientation;
+
+if (screen.lockOrientationUniversal(["landscape-primary", "landscape-secondary"])) {
+  // 方向已锁定成功
+} else {
+  // 方向锁定失败
+}
+ +

规范

+ + + + + + + + + + + + + + + + +
规范状态说明
{{SpecName('Screen Orientation', '', 'Screen Orientation')}}{{Spec2('Screen Orientation')}}Initial definition
+ +

浏览器兼容

+ +

{{CompatibilityTable}}

+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
FeatureChromeFirefox (Gecko)Internet ExplorerOperaSafari
基础支持{{CompatChrome(38)}}[1]{{CompatVersionUnknown}} {{property_prefix("moz")}}[2]11 {{property_prefix("ms")}}[3]{{CompatNo}}{{CompatNo}}
Array 参数{{CompatNo}}{{CompatGeckoDesktop("18.0")}}11 {{property_prefix("ms")}}{{CompatNo}}{{CompatNo}}
default{{CompatNo}}{{CompatNo}}{{CompatNo}}{{CompatNo}}{{CompatNo}}
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
FeatureAndroidChrome for AndroidFirefox Mobile (Gecko)IE MobileOpera MobileSafari Mobile
基础支持{{CompatNo}}{{CompatChrome(38)}}[1]{{CompatVersionUnknown}} {{property_prefix("moz")}}[2]{{CompatNo}}{{CompatNo}}{{CompatNo}}
Array 参数{{CompatNo}}{{CompatNo}}{{CompatGeckoMobile("18.0")}}{{CompatNo}}{{CompatNo}}{{CompatNo}}
default{{CompatNo}}{{CompatNo}}{{CompatGeckoMobile("26.0")}}{{CompatNo}}{{CompatNo}}{{CompatNo}}
+
+ +

[1] 使用更新的标准语法(screen.orientation.lock)实现类似的方法并返回一个 Promise 。虽然它存在于桌面上,但总是会失败。

+ +

[2] 此API仅作为Firefox OS和Firefox的前缀方法(screen.mozLockOrientation)实现。另外,由于{{Bug(966480)}},它不适用于Android的Firefox。

+ +

[3] 此方法在Internet Explorer for Windows 8.1和Windows RT 8.1中使用前缀(screen.msLockOrientation)实现。 它在Windows 7 上不受支持。

+ +

参见

+ + -- cgit v1.2.3-54-g00ecf