W3cubDocs

/DOM Events

levelchange

The levelchange event is fired when the level attribute of the battery API has changed.

General info

Specification
Battery
Interface
Event
Bubbles
No
Cancelable
No
Target
BatteryManager
Default Action
None

Properties

The event callback doesn't receive any event objects, but properties can be read from the BatteryManager object received from the navigator.getBattery method.

Property Type Description
BatteryManager.level double (float) The system's battery charging level scaled from 0 to 1.0. Returns 0 if the battery is empty and the system is about to suspend. Returns 1.0 if the battery is full, if the implementation is unable to report the battery's level, or if there is no battery attached to the system. Read only.

Example

navigator.getBattery().then(function(battery) {

  console.log("Battery level: " + battery.level * 100 + " %");

  battery.addEventListener('levelchange', function() {
    console.log("Battery level: " + battery.level * 100 + " %");
  });

});

© 2005–2017 Mozilla Developer Network and individual contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/Events/levelchange