From 0d495ad297d9e90ab35f54a822cd5e4e6a670713 Mon Sep 17 00:00:00 2001 From: MDN Date: Sun, 20 Jun 2021 00:37:04 +0000 Subject: [CRON] sync translated content --- .../web/api/ambient_light_events/index.html | 75 ++++++++++++++++++++++ .../orphaned/web/api/devicelightevent/index.html | 62 ++++++++++++++++++ 2 files changed, 137 insertions(+) create mode 100644 files/zh-cn/orphaned/web/api/ambient_light_events/index.html create mode 100644 files/zh-cn/orphaned/web/api/devicelightevent/index.html (limited to 'files/zh-cn/orphaned') diff --git a/files/zh-cn/orphaned/web/api/ambient_light_events/index.html b/files/zh-cn/orphaned/web/api/ambient_light_events/index.html new file mode 100644 index 0000000000..79a7ed9fbe --- /dev/null +++ b/files/zh-cn/orphaned/web/api/ambient_light_events/index.html @@ -0,0 +1,75 @@ +--- +title: Using Light Events +slug: orphaned/Web/API/Ambient_Light_Events +tags: + - WebAPI + - 事件 + - 环境光 +translation_of: Web/API/Ambient_Light_Events +original_slug: Web/API/Ambient_Light_Events +--- +
{{DefaultAPISidebar("Ambient Light Events")}}{{SeeCompatTable}}
+ +

环境光线事件是一个易用的让网页或应用感知光强变化的方法。它使网页或应用能对光强变化做出反应,例如改变用户界面的颜色对比度,或为拍照而改变曝光度。

+ +

光线事件

+ +

当设备的光线传感器检测到光强等级的变化时,它会向浏览器通知这个变化。当浏览器得到这个通知后,会发送(fire)一个提供光强信息的 {{domxref("DeviceLightEvent")}} 事件。

+ +

想要捕获这个事件,可用 {{domxref("EventTarget.addEventListener","addEventListener")}} 方法把事件处理器绑定到 window 上(使用 {{event("devicelight")}} 事件名),或者直接把事件处理器赋值给 {{domxref("window.ondevicelight")}} 属性。

+ +

该事件被捕捉后,可以从传入的事件对象上的 {{domxref("DeviceLightEvent.value")}} 属性获取光强(单位为 {{interwiki("wikipedia", "lux")}})。

+ +

示例

+ +
if ('ondevicelight' in window) {
+  window.addEventListener('devicelight', function(event) {
+    var body = document.querySelector('body');
+    if (event.value < 50) {
+      body.classList.add('darklight');
+      body.classList.remove('brightlight');
+    } else {
+      body.classList.add('brightlight');
+      body.classList.remove('darklight');
+    }
+  });
+} else {
+  console.log('不支持 devicelight 事件');
+}
+
+ +

规范

+ + + + + + + + + + + + + + + + +
规范状态备注
{{ SpecName('AmbientLight', '', 'Ambient Light Events') }}{{ Spec2('AmbientLight') }}首次定义
+ +

浏览器兼容性

+ + + +

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

+ +

Gecko 备注

+ +

{{event("devicelight")}} 事件在 Firefox Mobile for Android (15.0) 和 Firefox OS (B2G) 上实现并默认可用。从Gecko 22.0 {{geckoRelease("22.0")}} 开始,Mac OS X桌面版也可使用该事件。

+ +

参见

+ + diff --git a/files/zh-cn/orphaned/web/api/devicelightevent/index.html b/files/zh-cn/orphaned/web/api/devicelightevent/index.html new file mode 100644 index 0000000000..e3e717c514 --- /dev/null +++ b/files/zh-cn/orphaned/web/api/devicelightevent/index.html @@ -0,0 +1,62 @@ +--- +title: DeviceLightEvent +slug: orphaned/Web/API/DeviceLightEvent +tags: + - API + - Ambient Light Events + - Experimental + - Interface + - NeedsBetterSpecLink + - NeedsMarkupWork + - 事件 +translation_of: Web/API/DeviceLightEvent +original_slug: Web/API/DeviceLightEvent +--- +
{{apiref("Ambient Light Events")}}{{SeeCompatTable}}
+ +

DeviceLightEvent 为 Web 开发人员提供来自光传感器或类似设备的、关于附近环境光水平的信息。例如,基于当前环境光水平调节屏幕的亮度,以便节省电量或提供更好的阅读性。

+ +

属性

+ +
+
{{domxref("DeviceLightEvent.value")}}
+
环境光的亮度,单位为 {{interwiki("wikipedia", "lux")}}。
+
+ +

示例

+ +
window.addEventListener('devicelight', function(event) {
+  console.log(event.value);
+});
+ +

规范

+ + + + + + + + + + + + + + + + +
规范状态备注
{{ SpecName('AmbientLight', '', 'Ambient Light Events') }}{{ Spec2('AmbientLight') }}Initial specification
+ +

浏览器兼容性

+ + + +

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

+ +

参见

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