这应该准确显示我正在努力的方面: http://jsfiddle.net/PaulHighten/c5knqdgd/
<div class="panel-group" id="accordion" role="tablist" aria-multiselectable="true">
<div class="panel panel-default">
<div class="panel-heading" role="tab" id="headingParis">
<h4 class="panel-title">
<a class="collapsed" data-toggle="collapse" data-parent="#accordion" href="#collapseParis" aria-expanded="true" aria-controls="collapseParis">
Eiffel Tower, Paris
</a>
</h4>
</div>
<div id="collapseParis" class="panel-collapse collapse in" role="tabpanel" aria-labelledby="headingParis">
<div class="panel-body">
<div class="googlemap">
<iframe width="600" height="450" frameborder="0" style="border:0"
src="https://www.google.com/maps/embed/v1/place?q=Eiffel%20Tower%2C%20Avenue%20Anatole%20France%2C%20Paris%2C%20France&key=AIzaSyAFUKSu28KvFk67YcSlUWeUJ2TpcifSVmQ"></iframe>
</div>
</div>
</div>
</div>
<div class="panel panel-default">
<div class="panel-heading" role="tab" id="headingLondon">
<h4 class="panel-title">
<a class="collapsed" data-toggle="collapse" data-parent="#accordion" href="#collapseLondon" aria-expanded="false" aria-controls="collapseLondon">
Trafalgar Square, London
</a>
</h4>
</div>
<div id="collapseLondon" class="panel-collapse collapse" role="tabpanel" aria-labelledby="headingLondon">
<div class="panel-body">
<div class="googlemap">
<iframe width="600" height="450" frameborder="0" style="border:0"
src="https://www.google.com/maps/embed/v1/place?q=Trafalgar%20Square%2C%20London%2C%20United%20Kingdom&key=AIzaSyAFUKSu28KvFk67YcSlUWeUJ2TpcifSVmQ"></iframe>
</div>
</div>
</div>
</div>
巴黎小组正确显示地图,因为它有一个&#34;在&#34;。
伦敦小组没有那个类,这意味着bootstrap应用display:none;到那个小组。我假设阻止iframe正确运行它的http请求。
可以使用Google Maps Embed API来实现这一目标吗?我已经看到很多与API v3和initialize()调用相关的问题,但很难找到与使嵌入iframe代码相关的任何内容。
提前致谢。
=================
编辑:我使用的代码解决了问题(克里斯蒂娜的轻微修改答案仅更新相关的iframe一次):
$('[data-toggle="collapse"]').click('show.bs.collapse', function() {
var mapFrame = $($(this).attr('href') + ' .googlemap iframe');
if (!$(mapFrame).hasClass('map-refreshed')) {
mapFrame.attr('src', mapFrame.attr('src')+'');
mapFrame.addClass('map-refreshed');
}
});
答案 0 :(得分:2)
在shown.bs.collapse或show.bs.collapse函数
上刷新iframe源代码$('[data-toggle="collapse"]').click('shown.bs.collapse', function() {
var googleIframe = $('.googlemap iframe');
googleIframe.attr('src',googleIframe.attr('src')+'');
});
假设.googlemap是iframe的父级。
<2> Paul Highten的更新,所以它不会继续刷新:$('[data-toggle="collapse"]').click('show.bs.collapse', function() {
var mapFrame = $($(this).attr('href') + ' .googlemap iframe');
if (!$(mapFrame).hasClass('map-refreshed')) {
mapFrame.attr('src', mapFrame.attr('src')+'');
mapFrame.addClass('map-refreshed');
}
});