简体   繁体   中英

Incorrect page height in jQuery Mobile

I'm developing a web application using jQuery Mobile 1.2.0 and the page height is being calculated correctly on iOS and Android but not on Windows Phone, which has a gap on the bottom of the page.

Any idea how I can fix it, preferably only with 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>

This is a known issue. You may hardcode the min-height for body via CSS (portrait mode only) or do the following.

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

On Windows Phone 8 you can use the following

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

@Sergei's answer: The fix worked for my first page , but my other main pages have fixed footers which are still "floating" above a white space.

It is definitely less white space before though ( footers positioned slightly above the middle of the screen)

I tried to run the code again on page change and to change the body's, with class "ui-mobile-viewport" ,height but it did not work.

Hope you can help. Thank!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM