使用jQuery检测移动设备的旋转 [英] Detect mobile device rotation with jQuery

查看:133
本文介绍了使用jQuery检测移动设备的旋转的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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.

谢谢!

推荐答案

您可以使用jquery移动库定向更改事件.

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

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

这篇关于使用jQuery检测移动设备的旋转的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆