[英]Do Not Load iFrame Google Map Until Lightbox Click
I am embedding a few maps onto a page using the Google Maps iFrame Embed. 我正在使用Google Maps iFrame Embed将一些地图嵌入到页面上。 These maps are loaded into a page and displayed in a lightbox (with other information) upon click.
单击后,这些地图将加载到页面中并显示在灯箱中(带有其他信息)。 Is it possible to not load the iFrame content until the lightbox link is actually clicked?
在实际点击灯箱链接之前 ,是否可以不加载iFrame内容?
I do not want to load 10+ maps when only one or two might be needed. 当只需要一两个地图时,我不想加载10多个地图。
Is this possible to do? 这可能吗?
I am using Fancybox 2 as the lightbox and jQuery 2.1. 我正在使用Fancybox 2作为灯箱和jQuery 2.1。
I have considered using jQuery to inject the iFrame code on click but I am unsure of the best method. 我曾考虑过使用jQuery在单击时注入iFrame代码,但是我不确定最好的方法。
There may be different ways, 1 possible: 可能有不同的方式,其中一种可能是:
store the src
in another attribute of the iframe
(eg data-src
) and assign the src
when the lightbox opens: 将
src
存储在iframe
另一个属性中(例如data-src
),并在灯箱打开时分配src
:
$(".selector").fancybox({
afterLoad:function(){
this.content.find('iframe')
.each(function(i,f){
f=$(f);
if(!f.attr('src')) {
f.attr('src',f.data('src'));
}
});
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.