jquery - 谷歌地图(jQuery 脚本)不填充移动视口(viewport)上的页面高度

标签 jquery css django google-maps google-maps-api-3

我正在使用 Bootstrap 3 开发 Django 元素。目标是在导航栏下方以全页宽度和高度显示 Google map 。我能够在标准桌面视口(viewport)上这样做。但是,在移动屏幕宽度上, map 的顶部和底部会出现一个灰色区域。

桌面:http://screencast.com/t/3r0vBviNrK

手机:http://screencast.com/t/37YM8ifFdpw

我已将父 div 设置为 100% 并尝试使用绝对定位。

html + jQuery

<div id="map_wrapper">
    <div id="map_canvas" class="mapping"></div>
</div>

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>

<script>

    jQuery(function($) {
        // Asynchronously Load the map API 
        var script = document.createElement('script');
        script.src = "http://maps.googleapis.com/maps/api/js?sensor=false&callback=initialize";
        document.body.appendChild(script);
    });

    function initialize() {
        var map;
        var bounds = new google.maps.LatLngBounds();
        var mapOptions = {
            mapTypeId: 'roadmap'
        };

        // Display a map on the page
        map = new google.maps.Map(document.getElementById("map_canvas"), mapOptions);
        map.setTilt(45);

        // Multiple Markers   
        var markers = {{ marker_list|safe }};

        // Info Window Content
        var infoWindowContent = [

        {% for instance in queryset %}
            ['<div class="info_marker_content">' +
            '<a href="{{ instance.get_absolute_url }}"><img src="{{ instance.thumb }}" height="80" width="80"></a>' +
            '<h3><a class="location-font-map" href="{{ instance.get_absolute_url }}">{{ instance.location }}</a></h3>' +
            '<p><a class="qnote-font" href="{{ instance.get_absolute_url }}">{{ instance.quick_note }}</a></p>' +        '</div>'],
        {% endfor %}
        ];

        var infoWindow = new google.maps.InfoWindow(), marker, i;

        // Loop through our array of markers & place each one on the map  
        for( i = 0; i < markers.length; i++ ) {
            var position = new google.maps.LatLng(markers[i][1], markers[i][2], markers[i][3]);
            bounds.extend(position);
            marker = new google.maps.Marker({
                position: position,
                map: map,
                title: markers[i][0]
            });

            // Allow each marker to have an info window    
            google.maps.event.addListener(marker, 'click', (function(marker, i) {
                return function() {
                    infoWindow.setContent(infoWindowContent[i][0]);
                    infoWindow.open(map, marker);
                }
            })(marker, i));

            // Automatically center the map fitting all markers on the screen
            map.fitBounds(bounds);
        }       
    }

</script>

CSS

html, body {
    overflow-x: hidden;
    height: 100%;
    width: 100%;
    margin: 0px;
    padding: 0px;
}

#map_wrapper {
    height: 100%;
    width: 100%;
    position: absolute !important;
}

#map_canvas {
    width: 100%;
    height: 100%;
    margin: 0px;
    padding: 0px;
    position: absolute !important;
}

关于修复的任何想法?

最佳答案

尝试用 100vw 替换所有宽度值,用 100vh 替换所有高度值。

(代替 100%)。

100vw = 视口(viewport)宽度的 100% 100 vh = 视口(viewport)高度的 100%。

关于jquery - 谷歌地图(jQuery 脚本)不填充移动视口(viewport)上的页面高度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36817155/

相关文章:

javascript - 如何删除下拉边距?

html - 这个图灵完备规则 110 在 HTML5+CSS3 中的实现是如何工作的?

django - 你怎么知道 memcached 是否在做任何事情?

python - Django 静态文件不解决常量 404 错误

python - 我不断收到 'WSGIRequest' object has no attribute 'Get' on django

javascript - 在 javascript 或 jquery 中显示实时、日期、星期几

javascript - JavaScript 中的 3 级引号

javascript - 我正在尝试拆分此 "for"循环以创建 5 个不同的 DIV 元素

Javascript 密码验证

javascript - 我可以将 $(this) 传递给 .getJSON 回调函数吗?任何解决方法?