How can I display a full screen google map with jQuery Mobile?

前端 未结 4 2096
無奈伤痛
無奈伤痛 2021-01-18 06:05

The following code displays strange output. I should see a full screen mobile map. But for some reason it shows on just a portion of the screen. I am using jquery.ui

4条回答
  •  灰色年华
    2021-01-18 06:20

    I've been messing around with this for a bit, and managed to find the perfect solution. It caters for pages with or without a header. It will position the map perfectly in the space between the header and the bottom of the page (or on the whole page if a header is not present), for any resolution and any header height.

    This solution requires both CSS and JS if the page has a header, and CSS only if the page does not have a header.

    HTML

    CSS

    #map-canvas {
        position: absolute;
        width: 100%; 
        height: 100%;
        top: 0;
        left: 0;
    }
    
    /* eliminates scrollbars in map infowindow (optional) */
    #mappopup {
        line-height: 1.35;
        overflow: hidden;
        white-space: nowrap;
    }
    

    JS

    var mapPageHeader = $("#mapPage .ui-header").eq(0);
    if(mapPageHeader.length > 0) {
        var headerHeight = mapPageHeader.outerHeight();
        $("#map-canvas").css({
            'height': ($(window).height() - headerHeight + 1) + 'px',
            'top': headerHeight - 1
        });
    }
    

提交回复
热议问题