Google地图在隐藏div中显示为灰色 [英] Google maps shows up grey in hidden div

查看:286
本文介绍了Google地图在隐藏div中显示为灰色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经阅读了关于这个问题的堆栈上的许多线索,但没有任何东西能解决我的问题。我有一个标签上的谷歌地图,当页面加载时最初隐藏,并希望得到一些援助。以下是完整的代码:

 < script type =text / javascript> 
函数loadsinglemap(){
var mymap = new MeOnTheMap({
container:map_sidebar2,
html:<?php echo str_replace(''', ,$ post-> post_title);?>,
address:<?php echo str_replace('''','',get_post_meta($ post-> ID,map_location,true) );?>,
zoomLevel:15,

});

$ b $ j jQuery(document).ready(function(){loadsinglemap();})

< / script>

这是在显示地图的页面上:

< script type =text / javascript>
$(document).ready(function(){
$('a.contact')。click(function(){
google.maps.event.trigger(mymap,'resize ');
});
});
< / script>

我只是无法让它工作。如果有人看到有助于回复的内容。
谢谢


编辑:将元素选择器更改为类,并将我的链接改为类而不是ID,现在至少拿起它。我在firebug中发现mymap没有定义错误。

解决方案

在取消隐藏后再次调用initilize div。
我做到了,它工作。
JSFiddle


I have read the many threads on stack about this issue, but nothing will resolve my problem. I have the google map on a tab that is initially hidden when the page loads and would like some assistance please. Here is the full code:

<script type="text/javascript"> 
  function loadsinglemap(){
  var mymap = new MeOnTheMap({
  container: "map_sidebar2",
  html: "<?php echo str_replace('"',"",$post->post_title); ?>",
  address: "<?php echo str_replace('"','',get_post_meta($post->ID, "map_location", true)); ?>",
  zoomLevel: 15,

  });                        
  } 

 jQuery(document).ready(function() {   loadsinglemap();  })

 </script>

This is on the page where the map is displayed:

<script type="text/javascript">
$(document).ready(function(){
$('a.contact').click(function(){
google.maps.event.trigger(mymap, 'resize');
});
});
</script>

I just cannot get it to work. If anyone sees something that would help please respond. Thanks

EDIT: Changed the element selector to a class, and my link to a class instead of an ID and it now at least picks it up. I get an error in firebug that "mymap is not defined".

解决方案

call the initilize() function once again after you unhide the div. i did it and it worked. JSFiddle

这篇关于Google地图在隐藏div中显示为灰色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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