【问题标题】:Incorrect page height in jQuery MobilejQuery Mobile 中的页面高度不正确
【发布时间】:2012-10-23 10:23:33
【问题描述】:

我正在使用 jQuery Mobile 1.2.0 开发一个 Web 应用程序,并且在 iOS 和 Android 上可以正确计算页面高度,但在 Windows Phone 上却不能正确计算,因为 Windows Phone 在页面底部有一个间隙。

知道如何修复它,最好只使用 CSS 吗?

<!DOCTYPE html>
<html>
    <head>
        <title>Hello World jQuery Mobile</title>
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <link rel="stylesheet" href="css/jquery.mobile-1.2.0.min.css" /></script>
        <script type="text/javascript" src="js/jquery-1.8.2.min.js"></script>
        <script type="text/javascript" src="js/jquery.mobile-1.2.0.min.js"></script>
    </head>
    <body>
        <div data-role="page" style="background:green">
            <div data-role="header">
                <h1>Page Title</h1>
            </div>
            <div data-role="content">
                <p>Page content goes here.</p>
            </div>
            <div data-role="footer">
                <h4>Page Footer</h4>
            </div>
        </div>
    </body>
</html>

【问题讨论】:

标签: javascript jquery css windows-phone-7 jquery-mobile


【解决方案1】:

这是一个已知问题。您可以通过 CSS 硬编码 body 的最小高度(仅限纵向模式)或执行以下操作。

function bodyMinHeightFix() {
    var isWp7 = window.navigator.userAgent.indexOf("IEMobile/9.0") != -1;

    if (!isWp7) return;

    // portrait mode only
    if(window.innerHeight <= window.innerWidth) return;

    var zoomFactorW = document.body.clientWidth / screen.availWidth;

    // default value (web browser app)
    var addrBarH = 72;

    // no app bar in web view control
    if (typeof window.external.Notify !== "undefined") {
        addrBarH = 0;
    }

    var divHeightInDoc = (screen.availHeight-addrBarH) * zoomFactorW;
    //$("body")[0].style.minHeight = divHeightInDoc + 'px';

    var page = $("div[data-role='page']");
    if (page.length > 0)
        page[0].style.setProperty("min-height", divHeightInDoc + "px", 'important');

}

https://github.com/sgrebnov/jqmobile-metro-theme/blob/master/themes/metro/jquery.mobile.metro.theme.init.js

在 Windows Phone 8 上,您可以使用以下内容

@media screen and (orientation: portrait) {
    @-ms-viewport {
        width: 320px;
        user-zoom: fixed;
        max-zoom: 1;
        min-zoom: 1;
    }
}

@media screen and (orientation: landscape) {
    @-ms-viewport {
        width: 480px;
        user-zoom: fixed;
        max-zoom: 1;
        min-zoom: 1;
    }
}

【讨论】:

    【解决方案2】:

    @Sergei 的回答: 该修复适用于我的第一页,但我的其他主页有固定的页脚,这些页脚仍然“浮动”在空白区域上方。

    虽然之前的空白空间肯定更少(页脚略高于屏幕中间)

    我尝试在页面更改时再次运行代码并更改正文,使用类“ui-mobile-viewport”,高度,但它不起作用。

    希望您能提供帮助。 谢谢!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-01-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-02-10
      • 2013-11-02
      • 1970-01-01
      相关资源
      最近更新 更多