谷歌地图出现灰色内部模态引导 [英] google map appear with grey inside modal in bootstrap

查看:85
本文介绍了谷歌地图出现灰色内部模态引导的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Bootstrap v3.3.5( http://getbootstrap.com
Copyright 2011-2015 Twitter,Inc.为我的网站,我想添加谷歌地图。我运行这个代码,所有的地图都是灰色的。我不明白为什么这不适用于模态。有人能帮我吗 ?我还有include

$ html

pre $ lt; code>< body>
< a class =openmodalhref =#contactdata-toggle =modaldata-id =Peggy Guggenheim Collection - Venice>联系人< / a>
< div class =modal fadeid =contactrole =dialog>
< div class =modal-dialog modal-lg>
< div class =modal-contentid =back>
< div class =modal-header>
< h4>联系人< h4>
< / div>
< div class =modal-body>
< div id =map>< / div>
< / div>
< div class =modal-footer>
< / div>
< / div>
< / div>
< / body>

javascript

 < script src =https://maps.googleapis.com/maps/api/js>< / script> 
< script>
函数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>

style

 <风格> 
#map {
width:500px;
height:400px;
}
< / style>


这是上面的工作小提琴中的代码 - > http://jsfiddle.net/wgur1z7n/ (bootstrap 3.3.5)



在显示模式后触发Google地图 resize 事件:
$ ('shown.bs.modal',function(){
google。b $ b

  $('#contact')。 maps.event.trigger(map,resize); 
});


I use "Bootstrap v3.3.5 (http://getbootstrap.com) Copyright 2011-2015 Twitter, Inc. " for my site and i want to add google-map. I run this code, and all maps is grey. I dont understand why this not work with modal. Can someone help me ? I also have include

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>
 </body>

javascript

 <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>

style

<style>
  #map {
    width: 500px;
    height: 400px;
  }
</style>

解决方案

Here is the code above in a working fiddle -> http://jsfiddle.net/wgur1z7n/ (bootstrap 3.3.5)

Trigger the google maps resize event after the modal is shown :

$('#contact').on('shown.bs.modal', function () {
    google.maps.event.trigger(map, "resize");
});

这篇关于谷歌地图出现灰色内部模态引导的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆