jQuery Mobile:当手机处于纵向时,在加载时获取横向宽度 [英] JQuery Mobile: Grabbing landscape width on load when phone is in portrait

查看:83
本文介绍了jQuery Mobile:当手机处于纵向时,在加载时获取横向宽度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的移动应用程序处于protrait模式时正在抓住手机的横向宽度.我该如何解决?

My mobile app is grabbing the land-scape width of teh phone when it is in protrait mode. How do I fix this?

更具体地说:如果我加载应用程序并且我处于纵向视图,它将加载横向视图,这会将所有内容推向右侧.如果在横向视图中加载页面,一切正常.

To be more specific: if i load the application and I am in portrait view, it will load a landscape view, which is pushing everything to the right. If I load the page when in landscape view everything works.

如果我以纵向视图加载该应用程序,然后将其移至横向并向后移动,则纵向视图就可以了.这只是初始加载.

If I load the app in portrait view then move it to landscape and back, the portrait view is fine. It's just the initial load up.

这并不总是发生,实际上直到今天才开始发生.

Also this did not always happen, in fact it did not start happening until today.

我一直在做: <meta name="viewport" content="width=device-width, initial-scale=1">

但这是行不通的(因为它认为手机处于横向状态)

but that doesn't work (because it thinks the phone is in landscape)

我有0条线索在这里做什么.有没有一种方法可以迫使应用程序从横向跳下或重新加载一次,然后找到方向?

I have 0 clue what to do here. Is there a way to force the app to jump from landscape or reload once, then find the orientation?

编辑,我可以像这样调整方向:

Edit I can pick up the orientation like so:

       if (window.orientation == 0) {
            alert("portrait");
        } else {
            alert("landscape");
        }

如何编辑代码以确保从此处显示肖像CSS?

How can I edit the code to make sure the portrait css is showing from here?

推荐答案

也许是这样吗? http://www.roccles.com/?p=140

仅出于测试目的,将javascript的前几行修改为此:

Just for testing, modify the first few lines of that javascript to this:

if(window.orientation == 0){
    var ori = "portrait";
}else{
    var ori = "landscape";
}

alert(ori);

我很好奇您在初始页面加载时会收到什么警报.

I'm curious what alert you get on your initial page load.

这篇关于jQuery Mobile:当手机处于纵向时,在加载时获取横向宽度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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