jQuery Mobile 锁定方向 [英] jQuery Mobile lock orientation

查看:23
本文介绍了jQuery Mobile 锁定方向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 phonegap 和 jquery mobile 为 Android 手机构建应用程序.是否可以在一页上锁定方向?例如.页面地图"被加载并且方向被锁定到横向"模式.

I am using phonegap and jquery mobile to build an app for an android phone. Is there a possibility to lock the orientation on one page? E.g. page "map" is loaded and the orientation is locked to "landscape" mode.

推荐答案

我不这么认为.在 iOS 应用程序的 xCode 中是不可能的.我能想出的唯一解决方法是根据 window.orientation

Not really i think. In xCode for iOS apps is it not possible. The only fix I can come up with, is to rotate your body or a wrapper acording to window.orientation

$(window).bind("orientationchange", function(){
    var orientation = window.orientation;
    var new_orientation = (orientation) ? 0 : 180 + orientation;
    $('body').css({
        "-webkit-transform": "rotate(" + new_orientation + "deg)"
    });
});

这是一种冒险的方式,但认为这是唯一的方式..

This is a risky way but thinks its the only way..

希望对您有所帮助,请告诉我!

Hope this helps, please let me know !

参见:http://jsfiddle.net/aalouv/sABRQ/1/

或者,您可以绑定到窗口调整大小事件.

Alternative you can bind to the window resize event.

$(window).bind("resize", function(){
    var orientation = window.orientation;
    var new_orientation = (orientation) ? 0 : 180 + orientation;
    $('body').css({
        "-webkit-transform": "rotate(" + new_orientation + "deg)"
    });
});

<小时>

我不久前写了这个小脚本:它修复了 iOS safari 中的多次调整大小回调错误和 android 中的 non-/late-/early-trigger(1) 方向变化错误.


I wrote this little script a while ago: It fix the multiply resize callback bug in iOS safari and the non-/late-/early-trigger(1) orientationchange bug in android.

(1) 有时在浏览器更改宽度+高度之前有时不触发,有时不触发?有线!

(1) Sometimes it dosn't trigger sometimes before and some times after the browser has changes width + height? Wired!

if (!(/iphone|ipad/gi).test(navigator.appVersion)) {
    $(window).unbind("resize").bind("resize", function() {
        $(window).trigger("orientationchange");
    });
}

如果不是 iphone 或 ipad,您将触发窗口上的orientationchange 事件.

If not iphone or ipad you are triggering the orientationchange event on the window.

因此,当您绑定任何函数时,您所做的调整大小会引发orientationchange.

So when you will bind any function the the resize you do it throw orientationchange.

这篇关于jQuery Mobile 锁定方向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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