O'Reilly logo

PhoneGap Mobile Application Development Cookbook by Matt Gifford

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Updating a display object position through accelerometer events

Developers can make use of the accelerometer sensor and continual updates provided by it for many things including motion-detection games as well as updating the position of an object on the screen.

How to do it...

We will use the device's accelerometer sensor on continual update to move an element around the screen as a response to device movement. This is achieved through the following steps:

  1. Let's start by creating our initial HTML layout. Include the Cordova JavaScript reference in the head tag to import the required library.
  2. Within the body tag create two div elements. Set the first with the id attribute equal to dot. This will be the element we move around the screen of the device. ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required