问题
I'm building a web app in html5 at the moment that needs to be able to detect when the user shakes their phone and how fast they are shaking it. I've been browsing around but can't seem to find any examples of how I could implement this. I know html5 has an accelerometer that can detect the orientation of the phone, but how does it detect the speed at which the user is shaking it?
Also I'm testing this on my iPhone, although ideally I would like it to work on Android devices too. Thoughts? Examples would be great too. Thanks!
回答1:
You can use this jQuery plugin.
And you can also read this... http://www.html5rocks.com/en/tutorials/device/orientation/
The event, btw, must be supported by your mobile browser.
回答2:
Check this article.
DeviceOrientation is working on iOS and Android devices too.
来源:https://stackoverflow.com/questions/12334160/detecting-shaking-in-html5-mobile