forked from mdn/content
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
62 lines (43 loc) · 1.68 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
---
title: BatteryManager.level
slug: Web/API/BatteryManager/level
tags:
- API
- Battery API
- NeedsMarkupWork
- Property
- Reference
browser-compat: api.BatteryManager.level
---
<div>{{deprecated_header}}</div>
<div>{{APIRef("Battery API")}}</div>
<p>Indicates the current battery charge level as a value between <code>0.0</code> and
<code>1.0</code>.</p>
<h2 id="Syntax">Syntax</h2>
<pre class="brush: js">var level = battery.level</pre>
<p>On return, <code>level</code> is a number representing the system's battery charge
level scaled to a value between 0.0 and 1.0. A value of 0 means the
<code><em>battery</em></code>, which is a {{domxref("BatteryManager")}} object, is empty
and the system is about to be suspended. A value of 1.0 means the battery is full. A
value of 1.0 is also returned if the implementation isn't able to determine the battery
charge level or if the system is not battery-powered.</p>
<h2 id="Example">Example</h2>
<h3 id="HTML_Content">HTML Content</h3>
<pre class="brush: html language-html"><div id="level">(battery level unknown)</div>
</pre>
<h3 id="JavaScript_Content">JavaScript Content</h3>
<pre class="brush: js; ">navigator.getBattery().then(function(battery) {
var level = battery.level;
document.querySelector('#level').textContent = level;
});
</pre>
<p>{{ EmbedLiveSample('Example', '100%', 30, '', 'Web/API/BatteryManager/level') }}</p>
<h2 id="Specifications">Specifications</h2>
{{Specifications}}
<h2 id="Browser_compatibility">Browser compatibility</h2>
<p>{{Compat}}</p>
<h2 id="See_also">See also</h2>
<ul>
<li>{{domxref("BatteryManager")}}</li>
<li>{{domxref("Navigator.getBattery")}}</li>
</ul>