使用jQuery检测移动设备旋转

我正在寻找一个jQuery插件或Javascript库,它使用G传感器检测设备的旋转程度,而不仅仅是方向。 我知道可以做到 – 检查http://wagerfield.github.io/parallax/ – 但我还没有找到这样的东西。

如果它创造了一种可以实时更新的全局,那就太棒了。

谢谢!

你可以使用jquery mobile lib orientationchange事件。

$(window).on("orientationchange",function(event){ var x = event.beta, // -180 to 180 y = event.gamma, // -90 to 90 z = event.alpha; // 0 to 360 }); 

没有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 }); 

也尝试这个..

 if (window.DeviceOrientationEvent) { window.addEventListener('deviceorientation', function(event){ }); }