diff options
author | Juan Vásquez <juan@logicalbricks.com> | 2022-02-10 08:29:50 -0600 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-02-10 10:29:50 -0400 |
commit | bfccebc9d9515b6ed41e792ab4acb4b13e69ebbe (patch) | |
tree | 7f8025b3bab488872c4da2f1efcd8ed2968f3847 /files/es/web/api/batterymanager/onlevelchange/index.md | |
parent | 22a9aff4b54b712d760d1619a3f769623bf71407 (diff) | |
download | translated-content-bfccebc9d9515b6ed41e792ab4acb4b13e69ebbe.tar.gz translated-content-bfccebc9d9515b6ed41e792ab4acb4b13e69ebbe.tar.bz2 translated-content-bfccebc9d9515b6ed41e792ab4acb4b13e69ebbe.zip |
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>
Diffstat (limited to 'files/es/web/api/batterymanager/onlevelchange/index.md')
-rw-r--r-- | files/es/web/api/batterymanager/onlevelchange/index.md | 66 |
1 files changed, 66 insertions, 0 deletions
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 +<div id="level">(nivel de batería desconocido)</div> +<div id="stateBattery">(estado de carga desconocido)</div> +``` + +### 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")}} + |