我正在寻找一个 jQuery 插件或 Javascript 库,它们使用 G 传感器检测设备的旋转度数,而不仅仅是方向。我知道可以做到 - 检查 http://wagerfield.github.io/parallax/ - 但我还没有设法找到这样的东西。
如果它创建一种实时更新的全局就太好了。
谢谢!
最佳答案
您可以使用 jquery 移动库 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){
});
}
关于javascript - 使用 jQuery 检测移动设备旋转,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21060833/