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

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

问题描述

嘿,我使用phonegap和jquery移动构建一个Android手机的应用程序。是否有可能在一页上锁定方向?例如。页面地图加载,方向锁定为横向模式。

Hey guys i'm 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.

推荐答案

在xCode的iOS应用程序是不可能的。我可以想出的唯一的解决方法是旋转你的身体或者一个包装符合 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中的multiply resize回调bug和android中的非/迟到/早触发(1)orientationchange错误。


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) t触发有时之前和有些时候浏览器有改变宽度+高度? Wired!

(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天全站免登陆