Google 地图 V3 在隐藏 div 中偏离中心
我在 div 中有一个谷歌地图,默认情况下我需要隐藏它
<div id="newpost" style="display:none;">
,当地图取消隐藏时,它的一部分不会呈现。我猜我必须在提交时重新加载地图。有人知道该怎么做吗?
谢谢!
这是我的代码:
<script type="text/javascript">
jQuery(document).ready(function(){
jQuery('#newcatchhide').live('click', function(event) {
jQuery('#newpost').toggle('show');
});
});
这是 body 标记上的地图 oad 函数:
<body onload="load()" onunload="GUnload()">
这是切换的 div,以及包含地图的 div:
<div id="newpost" style="display:none;">
<div id="map" style="width: 500px; height: 300px"></div>
I have a google map inside a div that I need to be hidden by default
<div id="newpost" style="display:none;">
When the map is unhidden a part of it isn't rendering. I'm guessing I have to reload the map onSubmit. Anybody know how to do this?
Thanks!
Here's my code:
<script type="text/javascript">
jQuery(document).ready(function(){
jQuery('#newcatchhide').live('click', function(event) {
jQuery('#newpost').toggle('show');
});
});
This is the map oad function on the body tag:
<body onload="load()" onunload="GUnload()">
Here is the div that is toggled, and the div that contains the map:
<div id="newpost" style="display:none;">
<div id="map" style="width: 500px; height: 300px"></div>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
像这样的东西吗? http://jsbin.com/imuri5
这个想法是在显示 DIV 之后初始化地图。
编辑:
好的,根据您的更新将:替换
为:
然后从 body 标记中删除
onload="load()"
Something like this? http://jsbin.com/imuri5
The idea is to initialize the map after displaying the DIV.
EDIT:
Ok based on your update replace:
with:
And then remove
onload="load()"
from the body tag我最近自己也遇到了同样的问题,并发现修复非常简单:
其中
map
是您的谷歌地图实例。您可以在使 div 可见后调用此方法。
如果你使用 jQuery 来绘制地图,你可以使用
I recently had this same issue myself and discovered the fix to be quite simple:
Where
map
is your google map instance.You can call this after you make your div visible.
If you use jQuery for the map, you can use
更好:
并在显示点击事件中:
better:
and in show click event: