我使用“Bootstrap v3.3.5(http://getbootstrap.com http://getbootstrap.com)
版权所有 2011-2015 Twitter, Inc.“对于我的网站,我想添加谷歌地图。我运行此代码,所有地图都是灰色的。我不明白为什么这不适用于模式。有人可以帮助我吗?
我还包括了<script src="https://maps.googleapis.com/maps/api/js"></script>
.
HTML:
<body>
<a class="openmodal" href="#contact" data-toggle="modal" data-id="Peggy Guggenheim Collection - Venice">Contact</a>
<div class="modal fade" id="contact" role="dialog">
<div class="modal-dialog modal-lg">
<div class="modal-content" id="back">
<div class="modal-header">
<h4>Contact<h4>
</div>
<div class="modal-body">
<div id="map"></div>
</div>
<div class="modal-footer">
<a class="btn btn-default" data-dismiss="modal">Close</a>
</div>
</div>
</div>
JS:
<script src="https://maps.googleapis.com/maps/api/js"></script>
<script>
function initialize() {
var mapCanvas = document.getElementById('map');
var mapOptions = {
center: new google.maps.LatLng(44.5403, -78.5463),
zoom: 8,
mapTypeId: google.maps.MapTypeId.ROADMAP
}
var map = new google.maps.Map(mapCanvas, mapOptions)
}
google.maps.event.addDomListener(window, 'load', initialize);
</script>
CSS:
#map {
width: 500px;
height: 400px;
}
Here is the code above in a working fiddle -> http://jsfiddle.net/wgur1z7n/ http://jsfiddle.net/wgur1z7n/ (bootstrap 3.3.5)
触发谷歌地图resize
显示模态后的事件:
$('#contact').on('shown.bs.modal', function () {
google.maps.event.trigger(map, "resize");
});
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)