【问题标题】:Google Map extends off edge of page when embedded inside jQuery Mobile "page"嵌入 jQuery Mobile“页面”时,Google 地图会超出页面边缘
【发布时间】:2011-05-06 14:09:19
【问题描述】:

我正在开发一个小型地图应用程序,它在 jQuery Mobile“页面”中嵌入了 Google 地图。我希望地图占据屏幕的整个水平宽度,但仅此而已。我遇到的问题是地图“溢出”了右侧页面的边缘,可能有 5% 左右。这可以在http://www.codeemporium.com/experiments/map6.html 看到(抱歉,暂时不会在 Firefox 中显示),您会注意到在地图通常显示“使用条款”的右下角,它已被切断。我正在使用的主要 jQuery Mobile“页面”的 HTML 代码摘录如下(可以在上述页面的源代码中看到):`

<div data-role="page" style="width:100%; height:100%;" id="main_page"> 


<div data-role="content" id="map_canvas" style="width:100%;height:80%;">  
</div> 

<div data-role="footer" style="width:100%;height:20%;"> 
  <div data-role="navbar"> 
<ul> 
  <li><a href="#welcome" data-icon="info" data-iconpos="notext"></a></li> 
  <li><a href="#settings" data-icon="gear" data-iconpos="notext"></a></li> 
  <li><a href="#tracking" data-icon="alert" data-iconpos="notext"></a></li> 
      <li><a href="#search" data-icon="search" data-iconpos="notext"></a></li> 
</ul> 
  </div><!-- /navbar --> 
</div> 

`

地图被注入map_canvas div。在我的机器上使用 Chrome 开发人员,我可以看到地图画布最终为 1295 像素宽,这比我的屏幕的 1280 像素分辨率减去滚动条等略大。我遇到的问题是,我在解决我想象的样式问题方面几乎没有经验,甚至可能与上面的代码 sn-p 没有直接关系。除了这个问题的具体解决方案之外,如果有人可以建议如何以某种有条理的方式调试这些东西,也将不胜感激。

【问题讨论】:

    标签: css google-maps overflow jquery-mobile


    【解决方案1】:

    当我们遇到这个问题时,我们不得不做这个函数:

    function resizeMap () {
        $('#map_canvas').height($(window).height()-$('#map_head').height()); 
        // in your case #map_head would be .ui-navbar I believe
    }
    $(window).resize(function(){resizeMap(); map.setCenter(latlng)});
    

    您可以在 $(document).ready() 或地图初始化中运行 resizeMap()。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-03-16
      • 2011-12-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-11-24
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多