aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/web/api/batterymanager
diff options
context:
space:
mode:
Diffstat (limited to 'files/zh-cn/web/api/batterymanager')
-rw-r--r--files/zh-cn/web/api/batterymanager/charging/index.html121
-rw-r--r--files/zh-cn/web/api/batterymanager/index.html128
2 files changed, 249 insertions, 0 deletions
diff --git a/files/zh-cn/web/api/batterymanager/charging/index.html b/files/zh-cn/web/api/batterymanager/charging/index.html
new file mode 100644
index 0000000000..dd836b7730
--- /dev/null
+++ b/files/zh-cn/web/api/batterymanager/charging/index.html
@@ -0,0 +1,121 @@
+---
+title: 电池管理器
+slug: Web/API/BatteryManager/charging
+tags:
+ - 电池 API
+translation_of: Web/API/BatteryManager/charging
+---
+<pre class="syntaxbox">{{APIRef("Battery API")}}</pre>
+
+<p>指示设备电池当前是否正在充电的Boolean值</p>
+
+<h2 id="Syntax_句法">Syntax 句法</h2>
+
+<pre class="syntaxbox">var <em>charging</em> = battery.charging</pre>
+
+<p>返回当前是否正在对 {{domxref("BatteryManager")}} 对象的设备充电,如果正在充电则返回 <code>true</code>,否则返回 <code>false</code>.</p>
+
+<h2 id="Example" name="Example">Example 例子</h2>
+
+<h3 id="HTML_Content_(内容)">HTML Content (内容)</h3>
+
+<pre class="brush: html">&lt;div id="charging"&gt;(charging state unknown)&lt;/div&gt;</pre>
+
+<h3 id="JavaScript_内容">JavaScript 内容</h3>
+
+<pre class="brush: js; highlight:[3]">navigator.getBattery().then(function(battery) {
+
+ var charging = battery.charging;
+
+ document.querySelector('#charging').textContent = charging ;
+});</pre>
+
+<p>{{ EmbedLiveSample('Example', '100%', 30) }}</p>
+
+<h2 id="Specifications_规格">Specifications 规格</h2>
+
+<table class="standard-table">
+ <thead>
+ <tr>
+ <th scope="col">Specification</th>
+ <th scope="col">Status</th>
+ <th scope="col">Comment</th>
+ </tr>
+ </thead>
+ <tbody>
+ <tr>
+ <td>{{SpecName("Battery API")}}</td>
+ <td>{{Spec2("Battery API")}}</td>
+ <td>Initial definition</td>
+ </tr>
+ </tbody>
+</table>
+
+<h2 id="Browser_compatibility浏览器兼容性CompatibilityTable">Browser compatibility浏览器兼容性<span style="color: #3b3c40; font-size: 14px; font-weight: normal; line-height: 1.5;">{{CompatibilityTable}}</span></h2>
+
+<div id="compat-desktop">
+<table class="compat-table">
+ <tbody>
+ <tr>
+ <th>Feature</th>
+ <th>Chrome</th>
+ <th>Firefox (Gecko)</th>
+ <th>Internet Explorer</th>
+ <th>Opera</th>
+ <th>Safari</th>
+ </tr>
+ <tr>
+ <td>Basic support</td>
+ <td>{{CompatChrome(39.0)}}</td>
+ <td>{{CompatGeckoDesktop("10")}} {{property_prefix("moz")}}<br>
+ {{CompatGeckoDesktop("16")}}<sup>[1]</sup><br>
+ {{CompatGeckoDesktop("52")}}<sup>[3]</sup></td>
+ <td>{{CompatNo}}</td>
+ <td>25</td>
+ <td>{{CompatNo}}</td>
+ </tr>
+ </tbody>
+</table>
+</div>
+
+<div id="compat-mobile">
+<table class="compat-table">
+ <tbody>
+ <tr>
+ <th>Feature</th>
+ <th>Android</th>
+ <th>Android Webview</th>
+ <th>Firefox Mobile (Gecko)</th>
+ <th>IE Mobile</th>
+ <th>Opera Mobile</th>
+ <th>Safari Mobile</th>
+ <th>Chrome for Android</th>
+ </tr>
+ <tr>
+ <td>Basic support</td>
+ <td>{{CompatNo}}</td>
+ <td>{{CompatChrome(40.0)}}</td>
+ <td>{{CompatGeckoMobile("10")}} {{property_prefix("moz")}}<br>
+ {{CompatGeckoMobile("16")}}<sup>[1]</sup><br>
+ {{CompatGeckoMobile("52")}}<sup>[3]</sup></td>
+ <td>{{CompatNo}}</td>
+ <td>25<sup>[2]</sup></td>
+ <td>{{CompatNo}}</td>
+ <td>{{CompatChrome(42.0)}}<sup>[2]</sup></td>
+ </tr>
+ </tbody>
+</table>
+</div>
+
+<p>[1] Disabled by default in Firefox 10.0, but can be enabled setting the preference <code>dom.battery.enabled</code> to <code>true</code>. Starting with Firefox 11.0, <code>mozBattery</code> is enabled by default. The Battery API is currently supported on Android, Windows, and Linux with UPower installed. Support for MacOS is available starting with Gecko 18.0 {{geckoRelease("18.0")}}. Firefox also provide support for the deprecated {{domxref("navigator.battery")}}.</p>
+
+<p>[2] Values for {{domxref("BatteryManager.chargingTime")}} and {{domxref("BatteryManager.dischargingTime")}} are always equal to <code>Infinity</code>.</p>
+
+<p>[3] From Firefox 52 onwards, the Battery Status API is only available in chrome/privileged code.</p>
+
+<h2 id="See_also_也可以看看">See also 也可以看看</h2>
+
+<ul>
+ <li>{{domxref("BatteryManager")}}</li>
+ <li>{{domxref("Navigator.getBattery")}}</li>
+</ul>
diff --git a/files/zh-cn/web/api/batterymanager/index.html b/files/zh-cn/web/api/batterymanager/index.html
new file mode 100644
index 0000000000..050fc2a432
--- /dev/null
+++ b/files/zh-cn/web/api/batterymanager/index.html
@@ -0,0 +1,128 @@
+---
+title: BatteryManager(电源管理)
+slug: Web/API/BatteryManager
+translation_of: Web/API/BatteryManager
+---
+<p>{{APIRef}}</p>
+
+<p>BatteryManager 接口提供方法获取系统电量。 </p>
+
+<p>{{domxref("navigator.getBattery")}} 方法返回一个promise对象,该promise将提供一个BatteryManager接口,你可以从<a href="/en-US/docs/Web/API/Battery_Status_API">Battery Status API</a> 查询到相关信息。</p>
+
+<h2 id="属性">属性</h2>
+
+<dl>
+ <dt>{{domxref("BatteryManager.charging")}} {{ReadOnlyInline}}</dt>
+ <dd>一个布尔值,说明当前电池是否正在充电。</dd>
+ <dt>{{domxref("BatteryManager.chargingTime")}} {{ReadOnlyInline}}</dt>
+ <dd>一个数字,代表距离充电完毕还需多少秒,如果为0则充电完毕。</dd>
+ <dt>{{domxref("BatteryManager.dischargingTime")}} {{ReadOnlyInline}}</dt>
+ <dd>一个数字,代表距离电池耗电至空且挂起需要多少秒。</dd>
+ <dt>{{domxref("BatteryManager.level")}} {{ReadOnlyInline}}</dt>
+ <dd>一个数字,代表电量的放大等级,这个值在 0.0 至 1.0 之间。</dd>
+</dl>
+
+<h3 id="事件处理器">事件处理器</h3>
+
+<dl>
+ <dt>{{domxref("BatteryManager.onchargingchange")}}</dt>
+ <dd>{{event("chargingchange")}}事件处理器;电池充电状态更新时被调用。</dd>
+ <dt>{{domxref("BatteryManager.onchargingtimechange")}}</dt>
+ <dd>{{event("chargingtimechange")}}事件处理器;电池充电时间更新时被调用。</dd>
+ <dt>{{domxref("BatteryManager.ondischargingtimechange")}}</dt>
+ <dd>{{event("dischargingtimechange")}}事件处理器;电池断开充电时间更新时被调用。</dd>
+ <dt>{{domxref("BatteryManager.onlevelchange")}}</dt>
+ <dd>{{event("levelchange")}}事件处理器;电池电量更新时被调用。</dd>
+</dl>
+
+<h2 id="方法">方法</h2>
+
+<p>继承自{{domxref("EventTarget")}}:</p>
+
+<p>{{page("/zh-CN/docs/Web/API/EventTarget","Methods")}}</p>
+
+<h2 id="规格Specifications">规格Specifications</h2>
+
+<table class="standard-table">
+ <thead>
+ <tr>
+ <th scope="col">Specification</th>
+ <th scope="col">Status</th>
+ <th scope="col">Comment</th>
+ </tr>
+ </thead>
+ <tbody>
+ <tr>
+ <td>{{SpecName("Battery API")}}</td>
+ <td>{{Spec2("Battery API")}}</td>
+ <td>Initial definition</td>
+ </tr>
+ </tbody>
+</table>
+
+<h2 id="浏览器兼容性">浏览器兼容性</h2>
+
+<p>{{CompatibilityTable}}</p>
+
+<div id="compat-desktop">
+<table class="compat-table">
+ <tbody>
+ <tr>
+ <th>Feature</th>
+ <th>Chrome</th>
+ <th>Firefox (Gecko)</th>
+ <th>Internet Explorer</th>
+ <th>Opera</th>
+ <th>Safari</th>
+ </tr>
+ <tr>
+ <td>基本支持</td>
+ <td>{{CompatChrome(39.0)}}</td>
+ <td>{{CompatGeckoDesktop("10")}} {{property_prefix("moz")}}<br>
+ {{CompatGeckoDesktop("16")}}<sup>[1]</sup></td>
+ <td>{{CompatNo}}</td>
+ <td>25</td>
+ <td>{{CompatNo}}</td>
+ </tr>
+ </tbody>
+</table>
+</div>
+
+<div id="compat-mobile">
+<table class="compat-table">
+ <tbody>
+ <tr>
+ <th>Feature</th>
+ <th>Android</th>
+ <th>Android Webview</th>
+ <th>Firefox Mobile (Gecko)</th>
+ <th>IE Mobile</th>
+ <th>Opera Mobile</th>
+ <th>Safari Mobile</th>
+ <th>Chrome for Android</th>
+ </tr>
+ <tr>
+ <td>基本支持</td>
+ <td>{{CompatNo}}</td>
+ <td>{{CompatChrome(40.0)}}</td>
+ <td>{{CompatGeckoMobile("10")}} {{property_prefix("moz")}}<br>
+ {{CompatGeckoMobile("16")}}<sup>[1]</sup></td>
+ <td>{{CompatNo}}</td>
+ <td>25<sup>[2]</sup></td>
+ <td>{{CompatNo}}</td>
+ <td>{{CompatChrome(42.0)}}<sup>[2]</sup></td>
+ </tr>
+ </tbody>
+</table>
+</div>
+
+<p>[1] 在Firefox 10.0中默认无效,但可设定preference <code>dom.battery.enabled</code>为<code>true从而使其有效化。</code>自Firefox 11.0起,<code>mozBattery默认有效。</code>Battery API现能被支持与Android,Windows,和安装了UPower的Linux。自Gecko 18.0 {{geckoRelease("18.0")}}也能支持MacOS。Firefox还为被弃用的{{domxref("navigator.battery")}}提供支持。</p>
+
+<p>[2] {{domxref("BatteryManager.chargingTime")}}和{{domxref("BatteryManager.dischargingTime")}}的值总是等于无穷。</p>
+
+<h2 id="其他">其他</h2>
+
+<ul>
+ <li>The <a href="/zh-CN/docs/Web/API/Battery_Status_API">电池状态API</a></li>
+ <li>{{domxref("navigator.getBattery")}}</li>
+</ul>