-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
53 lines (45 loc) · 1.53 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
<!doctype html>
<html lang="es"><head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>HTML5 Battery API - Htmldesdecero.es</title>
<link rel="stylesheet" href="css/normalize.css">
<link rel="stylesheet" href="css/style.css">
<script src="js/jquery.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script>
$(document).ready(function() {
if ("getBattery" in navigator) {
navigator.getBattery().then(function(battery) {
var level = battery.level * 100;
var levelBar = $('.level');
if (battery.charging) {
levelBar.addClass('charging');
} else if (level > 65) {
levelBar.addClass('high');
} else if (level >= 35) {
levelBar.addClass('med');
} else {
levelBar.addClass('low');
}
if (!battery.charging) {
levelBar.css('width', level + '%');
}
});
} else {
$('.level').text("API de batería no compatible");
}
});
</script>
</head>
<body>
<div class="demo-wrapper">
<div class="attention">
Vea esta demostración en navegadores compatibles, de lo contrario no funciona.
</div>
<div class="battery">
<div class="level">
</div>
</div>
</div>
</body>
</html>