Reputation: 855
I am searching for a jQuery-plugin or Javascript-library that detects the rotation of a device in degrees, not just orientation, using the G-sensor. I know it can be done - check http://wagerfield.github.io/parallax/ - but I haven't managed to find something like this yet.
It would be great if it created a kind of global that updates realtime.
Thanks!
Upvotes: 2
Views: 3326
Reputation: 119
you can use jquery mobile lib orientationchange event.
$(window).on("orientationchange",function(event){
var x = event.beta, // -180 to 180
y = event.gamma, // -90 to 90
z = event.alpha; // 0 to 360
});
without jQuery:
window.addEventListener('orientationchange', function(event){
var x = event.beta, // -180 to 180
y = event.gamma, // -90 to 90
z = event.alpha; // 0 to 360
});
also try this..
if (window.DeviceOrientationEvent) {
window.addEventListener('deviceorientation', function(event){
});
}
Upvotes: 6