我正在使用 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/