HTML and CSS Reference
In-Depth Information
Battery API
For this example, you can either continue working with the code from the previous section
or, if you don't have access to a mobile phone, you can use the code from section I.3.3 as a
starting point. The changes required to the draw() function are shown next.
Listing I.30. Using the battery object in the draw function
As the annotation mentions, the battery object needs to be passed in, which necessitates
a small change in the go() function. The next listing shows the code for getting a reference
to the battery status and passing it to wilson.draw() .
Listing I.31. Passing the battery object to the draw() function
var battery = navigator . battery ||
navigator . mozBattery ||
navigator . webkitBattery ;
wilson . draw ( canvas , battery );
Search WWH ::

Custom Search