MDN wants to learn about developers like you: https://qsurvey.mozilla.com/s3/MDN-dev-survey

この記事はまだボランティアによって 日本語 に翻訳されていません。ぜひ MDN に参加して翻訳を手伝ってください!
この記事を English (US) で読むこともできます。

Obsolete
This feature is obsolete. Although it may still work in some browsers, its use is discouraged since it could be removed at any time. Try to avoid using it.

The chargingchange event is fired when the charging 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.charging boolean The system's battery charging status. Returns true if the battery is charging, if the state of the system's battery is not determinable, or if no battery is attached to the system. Returns false if the battery is discharging. Read only.

Example

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

  console.log("Battery charging? " + (battery.charging ? "Yes" : "No"));

  battery.addEventListener('chargingchange', function() {
    console.log("Battery charging? " + (battery.charging ? "Yes" : "No"));
  });

});

ドキュメントのタグと貢献者

タグ: 
 最終更新者: chrisdavidmills,