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

{{APIRef("Screen Wake Lock API")}}{{SeeCompatTable}}{{securecontext_header}}

+ +

WakeLock 接口允许一个文件获取屏幕唤醒锁定。

+ +

方法

+ +
+
{{domxref("WakeLock.request","WakeLock.request()")}}
+
返回一个决议为 {{DOMxRef("WakeLockSentinel")}} 的 {{JSxRef("Promise")}} 或当唤醒锁定不可访问的时候抛出异常。
+
+ +

示例

+ +

以下例子获取一个唤醒锁定并在 10 分钟后释放它:

+ +
function tryKeepScreenAlive(minutes) {
+  navigator.wakeLock.request("screen").then(lock => {
+    setTimeout(() => lock.release(), minutes * 60 * 1000);
+  });
+}
+
+tryKeepScreenAlive(10);
+
+ +

规范

+ + + + + + + + + + + + + + + + +
规范状态Comment
Screen Wake Lock APIEditor's DraftInitial definition
+ +

浏览器兼容性

+ +
+ + +

{{Compat("api.WakeLock")}}

+ +

相关链接

+ + +
diff --git a/files/zh-cn/web/api/wakelock/request/index.html b/files/zh-cn/web/api/wakelock/request/index.html new file mode 100644 index 0000000000..11605b1ab9 --- /dev/null +++ b/files/zh-cn/web/api/wakelock/request/index.html @@ -0,0 +1,86 @@ +--- +title: WakeLock.request() +slug: Web/API/WakeLock/request +translation_of: Web/API/WakeLock/request +--- +

{{APIRef("Screen Wake Lock API")}}{{SeeCompatTable}}{{securecontext_header}}

+ +

WakeLock.request() 方法用来获取屏幕唤醒锁定权限,防止屏幕变暗、关闭或展示屏幕保护程序。

+ +

语法

+ +
WakeLock.request(wakeLockType)
+ +

参数

+ +
+
wakeLockType
+
唤醒锁定类型,目前必须传 "screen"
+
+ +

返回值

+ +

决议为 {{DOMxRef("WakeLockSentinel")}} 的 {{JSxRef("Promise")}}。

+ +

异常

+ +
+
NotAllowedError
+
当唤醒锁定不可用的时候抛出,例如在: +
    +
  • 由于屏幕唤醒锁定策略,Document 不允许使用屏幕唤醒锁定。
  • +
  • Document 不完全激活。
  • +
  • Document 被隐藏。
  • +
  • {{Glossary("User Agent")}} 无法获取平台的唤醒锁定。
  • +
+
+
+ +

示例

+ +

以下示例获取屏幕唤醒锁定并在 10 分钟后释放它:

+ +
function tryKeepScreenAlive(minutes) {
+  navigator.wakeLock.request("screen").then(lock => {
+    setTimeout(() => lock.release(), minutes * 60 * 1000);
+  });
+}
+
+tryKeepScreenAlive(10);
+
+ +

规范

+ + + + + + + + + + + + + + + + +
规范状态Comment
Screen Wake Lock APIEditor's DraftInitial specification.
+ +

浏览器兼容性

+ + + +

{{Compat("api.WakeLock.request")}}

+ +

相关链接

+ + + +

+ +

-- cgit v1.2.3-54-g00ecf