【问题标题】:css media queries replace map with embed imageCSS媒体查询用嵌入图像替换地图
【发布时间】:2015-06-28 15:10:47
【问题描述】:

我正在尝试将索引页上的 gmap 替换为用于移动设备的嵌入式图像版本。该地图在桌面上看起来不错,但是当我在移动设备上查看它时,它太长了,并且由于 gmap 的原因,滚动到页面末尾很有挑战性。 我在 JS 上设置了“scrollwheel:false”,它为桌面修复了这个问题,但在移动设备上仍然不起作用。我还将地图宽度设置为 90%,但地图在移动设备上看起来仍然很大。因此,一旦屏幕尺寸低于 767 像素,我决定将地图替换为嵌入的图像版本。唯一的问题是我不确定如何交换两者(gmap 到图像)。任何建议将不胜感激。

关于页面的一些细节,它正在使用 RoR 的“渲染”显示。

index.html:

<div id="map" class="google-maps">
     <%= render "gmap" %>
</div>

_gmap.html:

<script type="text/javascript">
    handler = Gmaps.build('Google');
    handler.buildMap({
       provider: {
          scrollwheel: false,
          mapTypeId: google.maps.MapTypeId.HYBRID,
          maxZoom: 64
       },
       internal: {
          id: 'map'
       }
    }, function() {
       markers = handler.addMarkers(<%=raw@hash.to_json%>);
       handler.bounds.extendWith(markers);
       handler.fitMapToBounds()
    });
    handler
</script>

gmap.css

.google-maps {  
    width: 90%; 
    height: 100%; 
    margin: 0 auto;
    position: absolute;
    top:0;
    z-index:1;
}

【问题讨论】:

    标签: javascript css ruby google-maps media-queries


    【解决方案1】:

    这是基础...

    我建议向上移动,而不是向下移动。或者 - 只是拆分它...

    如果您拉入地图...但随后将其替换为图像...这有点落后。 :)

    (已更新此链接...) http://codepen.io/sheriffderek/pen/lLwgk/

    $(function() {
    
      var wWidth = $(window).width();
    
      if (wWidth > 1200) {
    
        $('#yo').append('<img alt="big image" src="http://placehold.it/1200x800" />')
        // you can put any code in here... : )
    
      } else {
    
        $('#yo').append('<img alt="big image" src="http://placehold.it/600x400" />')
    
      }
    
    });
    



    http://codepen.io/sheriffderek/pen/azOyQV

    这也展示了如何将数据属性用于东西 - 可能不适合这个 - 但它会关注变化。

    【讨论】:

    • 如果你愿意,你可以变得更复杂 - 并注意调整大小。
    • 谢谢治安官。这非常适合将图像文件交换到另一个图像文件。谷歌地图 api 到嵌入的谷歌地图或图像文件怎么样?在屏幕宽度低于 767 像素后,类似的东西可以响应和交换吗?
    • 我不熟悉你的模板引擎,但这种方法只是一个if / else 声明 - 所以,你可以在里面放任何你想要的东西。不确定您的地图 API 需求。我会把它扔到一个函数中,然后附加它而不是按照你拥有它的方式包含它。再说一次,我想说,if the window is not bigger that 767px, insert the image, otherwise (767 or bigger) - append the map(我也强烈反对您针对特定的 iPad)
    猜你喜欢
    • 2014-06-02
    • 2016-06-04
    • 1970-01-01
    • 2015-09-02
    • 2019-05-21
    • 2017-07-22
    • 1970-01-01
    • 2013-05-19
    • 2015-06-08
    相关资源
    最近更新 更多