简体   繁体   English

当点击1然后谷歌地图不显示

[英]when click on 1 then google map not showing

Click herer For JS-FIDDLE 单击JS-FIDDLE的继承人

first of all i put the google map on the top, its showing well, but when i click on 1 then open det1 and in the det 1 div google map is not showing well i think its jquery conflation error. 首先,我将google map放在顶部,显示得很好,但是当我单击1然后打开det1,在det 1 div中,google map不能很好显示,我认为它的jquery合并错误。 please help, thanks in advance. 请帮助,在此先感谢。

here is jquery code: 这是jQuery代码:

jQuery('a[id^="prod"]').on('click', function (e) {
    var id = $(this).attr('id').slice(-1);
    var previs = $('div.product-detail:visible');
    $('div.product-detail').hide();
    if (previs.is($('.det' + id))) {
        $('.det' + id).hide()
    }
    else
    {
        $('.det' + id).show();
    }

    e.preventDefault()
});

It's not a jquery error. 这不是jQuery错误。 It's a google maps issue. 这是谷歌地图问题。 Once you render a google map, if you resize it or change it's visibility, you will frequently experience visual issues like partial rendering. 渲染Google地图后,如果调整其大小或更改其可见性,您将经常遇到视觉问题,例如部分渲染。

So, the problem is that you are generating the map while the iframe is still hidden, so when you show it, the map will have visual issues. 因此,问题在于您正在生成地图,而iframe仍处于隐藏状态,因此当您显示它时,地图将出现视觉问题。 Instead, load the map only after showing the iframe and it will work: 相反,仅在显示iframe后才加载地图,它将起作用:

HTML: HTML:

<div class="product-detail det1 cf">
    <div class="product-detail-row cf">1</div>
    <div class="directoria-map">
            <iframe src="" width="600" height="450" frameborder="0" style="border:0"></iframe>
            </div><!-- directoria-map -->
    <!-- .product-detail-row -->
</div>

JS: JS:

jQuery('a[id^="prod"]').on('click', function (e) {
    var id = $(this).attr('id').slice(-1);
    var previs = $('div.product-detail:visible');
    $('div.product-detail').hide();
    if (previs.is($('.det' + id))) {
        $('.det' + id).hide()
    }
    else
    {
        $('.det' + id).show();
        $('.det' + id).find("iframe").attr("src", "https://www.google.com/maps/embed?pb=!1m14!1m8!1m3!1d3988.526251756596!2d-48.4791421!3d-1.4581948999999998!3m2!1i1024!2i768!4f13.1!3m3!1m2!1s0x92a48e80253e4c21%3A0x2d5679c46276bb6!2sRua+dos+Mundurucus%2C+3100+-+Jurunas!5e0!3m2!1sen!2sbr!4v1402684785532");
    }

    e.preventDefault()
});

Try your fiddle updated: http://jsfiddle.net/hLd5W/25/ 尝试更新您的小提琴: http : //jsfiddle.net/hLd5W/25/

EDIT: 编辑:

You can create a custom attribute on the tag, so you can specify a different url to each iframe : 您可以在代码上创建自定义属性,因此可以为每个iframe指定不同的网址:

HTML: HTML:

 <!-- .product-main -->
<div class="product-detail det1 cf">
    <div class="product-detail-row cf">1</div>
    <div class="directoria-map">
            <iframe maps-url="https://www.google.com/maps/embed?pb=!1m14!1m8!1m3!1d3988.526251756596!2d-48.4791421!3d-1.4581948999999998!3m2!1i1024!2i768!4f13.1!3m3!1m2!1s0x92a48e80253e4c21%3A0x2d5679c46276bb6!2sRua+dos+Mundurucus%2C+3100+-+Jurunas!5e0!3m2!1sen!2sbr!4v1402684785532" src="" width="600" height="450" frameborder="0" style="border:0"></iframe>
            </div><!-- directoria-map -->
    <!-- .product-detail-row -->
</div>

JS: JS:

jQuery('a[id^="prod"]').on('click', function (e) {
    var id = $(this).attr('id').slice(-1);
    var previs = $('div.product-detail:visible');
    $('div.product-detail').hide();
    if (previs.is($('.det' + id))) {
        $('.det' + id).hide()
    }
    else
    {
        $('.det' + id).show();
        var url = $('.det' + id).find("iframe").attr("maps-url");
        $('.det' + id).find("iframe").attr("src", url);
    }

    e.preventDefault()
});

Updated fiddle: http://jsfiddle.net/hLd5W/26/ 更新的小提琴: http : //jsfiddle.net/hLd5W/26/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM