-
Notifications
You must be signed in to change notification settings - Fork 8
/
nivel-bateria.html
39 lines (28 loc) · 996 Bytes
/
nivel-bateria.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
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Nivel Batería con Battery API</title>
</head>
<body>
<h1>Nivel Batería con Battery API</h1>
<div>Nivel de Batería: <span id="batteryLevel"></span>%</div>
<script>
navigator.getBattery().then(function (battery) {
// Volcamos la información por consola
console.log("Nivel de batería " + battery.level * 100 + "%");
// Elemento del DOM
var batteryLevel = document.getElementById("batteryLevel");
batteryLevel.innerHTML = battery.level * 100;
battery.addEventListener('levelchange', function() {
batteryLevel.innerHTML = battery.level * 100;
console.log("Nivel de batería " + battery.level * 100 + "%");
});
});
</script>
<br/><br/>
<hr>
Artículo disponible en: <a href="http://lineadecodigo.com/html5/nivel-de-la-bateria-con-html5/">http://lineadecodigo.com/html5/nivel-de-la-bateria-con-html5/</a><br/>
<a href="http://lineadecodigo.com" title="Linea de Codigo">lineadecodigo.com</a>
</body>
</html>