Skip to content

Instantly share code, notes, and snippets.

@apeckham
Created August 6, 2012 16:50
Show Gist options
  • Save apeckham/3276533 to your computer and use it in GitHub Desktop.
Save apeckham/3276533 to your computer and use it in GitHub Desktop.
emulate devicemotion event using phonegap's watchAcceleration
$(document).on({
deviceready: function () {
if (!('ondevicemotion' in window)) {
navigator.accelerometer.watchAcceleration(function (acceleration) {
var event = document.createEvent('Event');
event.initEvent('devicemotion', true, true);
event.accelerationIncludingGravity = acceleration;
window.dispatchEvent(event);
}, $.noop, {frequency: 250});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment