Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javascript. Listen for iPhone shake event?

Is it possible to listen for an iPhone (or any mobile phone with accelerometer) shake event with JavaScript? You know like shaking the iPhone to shuffle the next song in iTunes I want to call a JS function on my website when the iPhone got shaken.

like image 519
matt Avatar asked Feb 04 '10 18:02

matt


2 Answers

In the latest iOS update (4.2) the accelorometer is now accessible from Javascript.

See: http://www.mobilexweb.com/blog/safari-ios-accelerometer-websockets-html5

like image 100
Olly Avatar answered Sep 19 '22 14:09

Olly


Here's an elegant implementation of shake detection using the accelerometer if anyone is looking for it:

https://github.com/alexgibson/shake.js

like image 39
Mr Speaker Avatar answered Sep 19 '22 14:09

Mr Speaker