From bfccebc9d9515b6ed41e792ab4acb4b13e69ebbe Mon Sep 17 00:00:00 2001 From: Juan Vásquez Date: Thu, 10 Feb 2022 08:29:50 -0600 Subject: 8. BatteryManager.onlevelchange [ES] (#4020) * 8. BatteryManager.onlevelchange [ES] - [x] change format form HTML to MD. - [x] update the whole content file Related #4019 * Update files/es/web/api/batterymanager/onlevelchange/index.md * Update files/es/web/api/batterymanager/onlevelchange/index.md Co-authored-by: David Brito <39559632+davbrito@users.noreply.github.com> * Add suggestions Co-authored-by: David Brito <39559632+davbrito@users.noreply.github.com> --- .../web/api/batterymanager/onlevelchange/index.md | 66 ++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 files/es/web/api/batterymanager/onlevelchange/index.md (limited to 'files/es/web/api/batterymanager/onlevelchange/index.md') diff --git a/files/es/web/api/batterymanager/onlevelchange/index.md b/files/es/web/api/batterymanager/onlevelchange/index.md new file mode 100644 index 0000000000..605dc5ba63 --- /dev/null +++ b/files/es/web/api/batterymanager/onlevelchange/index.md @@ -0,0 +1,66 @@ +--- +title: BatteryManager.onlevelchange +slug: Web/API/BatteryManager/onlevelchange +browser-compat: api.BatteryManager.onlevelchange +translation_of: Web/API/BatteryManager/onlevelchange +--- +{{deprecated_header}} {{APIRef("Battery API")}} + +La propiedad **`BatteryManager.onlevelchange`** especifica un detector +de eventos para recibir eventos de {{event("levelchange")}}. Estos eventos ocurren +cuando el {{domxref("BatteryManager.level", "level")}} de batería se actualiza. + +## Sintaxis + +```js +navigator.battery.onlevelchange = funcRef; +``` + +Donde `battery` es un objecto {{domxref("BatteryManager")}}, +y `funcRef` es una función que se convoca cuando el evento de {{event("levelchange")}} sucede. + +## Ejemplo + +### Contenido HTML + +```html +
(nivel de batería desconocido)
+
(estado de carga desconocido)
+``` + +### Contenido JavaScript + +```js +navigator.getBattery().then(function(battery) { + battery.onlevelchange = function(){ + document.querySelector('#level').textContent = battery.level; + + if(battery.charging) { + document.querySelector('#stateBattery').textContent = + "Charging time: " + (battery.chargingTime / 60); + } + else { + document.querySelector('#stateBattery').textContent = + "Discharging time: " + (battery.dischargingTime / 60); + } + }; +}); +``` + +### Resultado + +{{EmbedLiveSample('', '100%', 40)}} + +## Especificaciones + +{{Specifications}} + +## Compatibilidad con navegadores + +{{Compat}} + +## Véase también + +- {{domxref("BatteryManager")}} +- {{domxref("Navigator.getBattery")}} + -- cgit v1.2.3-54-g00ecf