2012-01-09 19 views
1

我正在使用地理编码显示带显示用户位置的Google地图。我正在寻找滑动菜单的地图。我遇到的问题是,当您打开滑动菜单时,地图只占用左上角的一个小区域,但只要调整浏览器窗口的大小,地图就会像我想要的那样占据整个区域。无论您调整浏览器窗口的大小,即使缩小浏览器窗口的大小,也会发生这种情况。让我知道如果你需要看到更多的我的代码比这地图不占用整个div

滑动菜单功能

$(document).ready(function() 
    { 
    $(".content").hide(); //updated line, removing the #panel ID. 
    $('#tab').toggle(function() //adding a toggle function to the #tab 
     { 
     $('#panel').stop().animate(
     { 
      width:"800px", opacity:0.8 //to adjust width of bar 
     } 
     , 500, function() //sliding the #panel to 200px 
     { 
      $('.content').fadeIn('slow'); //slides the content into view. 
     }); 
     }, 
    function() //when the #tab is next cliked 
    { 
     $('.content').fadeOut('slow', function() //fade out the content 
     { 
     $('#panel').stop().animate(
      { 
      width:"0", opacity:0.1 //slide the #panel back to a width of 0 
      } 
      , 500); 
     }); 
    }); 
    }); 

滑动菜单HTML

<div id="panel"> 
    <div class="content"> 
    <div id="mapContainer"></div> 
    </div> 
</div> 

CSS

#tab { 
    width: 30px; 
    height: 100px; 
    position: fixed; 
    left: 0px; 
    top: 100px; 
    display: block; 
    cursor: pointer; 
    background-color: #ff0000; 
    border-top-right-radius: 20px; 
    border-bottom-right-radius: 20px; 
} 

#panel { 
    position: fixed; 
    left: 0px; 
    top: 50px; 
    background-color: #ffffff; 
    height: 500px; 
    width: 0px; 
    border-top-right-radius: 20px; 
    border-bottom-right-radius: 20px; 
} 

#mapContainer { 
    height: 500px; 
    width: 800px; 
    border:10px solid #eaeaea; 
} 
+0

你的问题的工作示例将是非常有用的,如果你能提供一个。也许把一个在http://jsfiddle.net/? – ANeves 2012-01-09 10:38:31

+0

你能举个例子,让我们看看问题出在哪里 – 2012-01-09 10:38:56

+0

举一个例子,一旦标签被打开,你重新调整屏幕尺寸,它应该占用整个div的大小,除非刷新页面,否则无法再次重新创建问题。让我知道这个例子是否适用。 – Colin747 2012-01-09 11:22:38

回答

0

地图容器需要宽度和高度才能正确显示地图,但似乎动画会干扰这些值。

由于正确设置了宽度和高度并引发了resize事件,所以在浏览器调整大小时,该地图可以正常工作。

最快捷的解决问题的方法是调用调整大小的方法,当动画完成像这样:

google.maps.event.trigger(map, 'resize'); 

的jsfiddle更新:http://jsfiddle.net/uADHv/2/

+0

谢谢,非常感谢 – Colin747 2012-01-10 10:52:04