我有一个谷歌地图(v3),我正在放置几个标记,并希望能够点击标记并拉出Fancybox iFrame。我无法弄清楚如何将URL从标记拉入Fancybox。
我可以看到Fancybox触发 - 弹出窗口显示为breifly,然后链接被拉起作为当前页面顶部的新页面。
以下是相关代码的摘录:
var sites = [
['Mount Evans', 39.58108, -105.63535, 4, 'www.myurl-1.com'],
['Irving Homestead', 40.315939, -105.440630, 2, 'wwww.myurl-2.com'],
['Badlands National Park', 43.785890, -101.90175, 1, 'www.myurl-3.com'],
['Flatirons in the Spring', 39.99948, -105.28370, 3, 'www.myurl-4.com']
];
function setMarkers(map, markers) {
for (var i = 0; i < markers.length; i++) {
var sites = markers[i];
var siteLatLng = new google.maps.LatLng(sites[1], sites[2]);
var marker = new google.maps.Marker({
position: siteLatLng,
map: map,
title: sites[0],
zIndex: sites[3],
url: sites[4]
});
google.maps.event.addListener(marker, 'click', function() {
$.fancybox({
href : function() {
window.location.href = marker.url;
},
width : 1000,
maxHeight : 666,
fitToView : true,
autoSize : false,
type: 'iframe',
padding: 0,
openEffect : 'elastic',
openSpeed : 150,
aspectRatio : true,
closeEffect : 'elastic',
closeSpeed : 150,
closeClick : true,
iframe : { scrolling : 'no'
},
preload : true
});
});
}
}
答案 0 :(得分:0)
以下是我用来解决此问题的最终代码:
var sites = [
['Mount Evans', 39.58108, -105.63535, 4, 'www.myurl-1.com'],
['Irving Homestead', 40.315939, -105.440630, 2, 'wwww.myurl-2.com'],
['Badlands National Park', 43.785890, -101.90175, 1, 'www.myurl-3.com'],
['Flatirons in the Spring', 39.99948, -105.28370, 3, 'www.myurl-4.com']
];
function setMarkers(map, markers) {
for (var i = 0; i < markers.length; i++) {
var sites = markers[i];
var siteLatLng = new google.maps.LatLng(sites[1], sites[2]);
var marker = new google.maps.Marker({
position: siteLatLng,
map: map,
title: sites[0],
zIndex: sites[3],
href: sites[4]
});
google.maps.event.addListener(marker, 'click', function() {
$.fancybox({
href : sites[4],
width : 1000,
maxHeight : 666,
fitToView : true,
autoSize : false,
type: 'iframe',
padding: 0,
openEffect : 'elastic',
openSpeed : 150,
aspectRatio : true,
closeEffect : 'elastic',
closeSpeed : 150,
closeClick : true,
iframe : { scrolling : 'no'
},
preload : true
});
});
}
}
在标记选项中引用了href,并在fancybox调用中引用。
答案 1 :(得分:0)
另请查看此帖子打开DIV作为精美框Google Map Marker
$("a#fancyBoxLink").fancybox({
'href' : '#myDivID',
'titleShow' : false,
'transitionIn' : 'elastic',
'transitionOut' : 'elastic'
});