我正在尝试开发一个有两个容器的网页。mainmapdiv 覆盖整个页面,而 mainhomediv 位于 mainmapdiv 之上。我的目标是隐藏 mainhomediv 并在单击图像(id=mapbutton)时在 mainmapdiv 上显示谷歌地图。代码如下:
<script type="text/javascript">
var map;
function initialize() {
var mapOptions = {
center: new google.maps.LatLng(-34.397, 150.644),
zoom: 8,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById("mainmapdiv"),mapOptions);
}
google.maps.event.addDomListener(window, 'load', initialize);
</script>
<script>
var map;
$(document).ready(function(){
//Click on button to display map
$('#mapbutton').click(function(){
$('#mainhomediv').fadeTo("slow",0);
$('#mainhomediv').css({opacity: 0});
initialize();
});
//Click on Home to get back home div
$('#home').click(function(){
$('#mainhomediv').fadeTo("slow",1);
$('#mainhomediv').css({opacity: 1});
});
});
代码
<body>
<!--This is the primary container-->
<div id='#mainmapdiv' class='mainmapdiv'>
<div id='#mainhomediv' class='mainhomediv'>
.
//Somewhere in here there is an image with id='mapbutton'
.
.
</div>
</div>
</body>
现在,当我单击图像时,mainhomediv 完美隐藏,但地图未显示在 mainmapdiv 上。
我已导入以下脚本:
<script src="jquery-1.10.2.min.js"></script>
<script type="text/javascript" src="http://maps.googleapis.com/maps/apijs?sensor=false"></script>