Book Image

JavaScript Mobile Application Development

Book Image

JavaScript Mobile Application Development

Overview of this book

Table of Contents (15 chapters)
JavaScript Mobile Application Development
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Accelerometer


The accelerometer plugin provides access to the device's accelerometer in order to get the delta in movement relative to the current device's orientation in the x, y, and z axes.

In order to use the accelerometer in our Apache Cordova project, we need to use the following cordova plugin add command:

> cordova plugin add https://git-wip-us.apache.org/repos/asf/cordova-plugin-device-motion.git

Demo

In order to access the accelerometer demo, you need to click on the accelerometer list item. You will be introduced to the Accelerometer page. You can then click on the Start Watch Acceleration button in order to start watching the accelerometer. You will then be able to get the acceleration information in the x, y, and z axes, as shown in the following screenshot:

The Accelerometer page in action

You can click on the Stop Watch Acceleration button to stop watching the accelerometer at any time.

The HTML page

The following code snippet shows the "accelerometer" page:

<div data-role...