问题描述
在 ajax 请求的成功区域中,我通过 jQuery 添加了一个 onClick 事件监听器来打开fancybox。画廊的对象被接收并通过数据属性传递。
jQuery.ajax({
type: "post",dataType: "json",url: ajax_url,data: data,success: function( response ) {
poi_images = '';
if(poi_data['images'] !== undefined) {
poi_gallery_class = 'poi-gallery';
poi_images = JSON.stringify(poi_data['images']);
}
// [...]
$('.poi-gallery').on('click',function() {
gallery = $(this).attr('data-gallery');
gallery = JSON.parse(gallery);
console.log(gallery);
$.fancybox.open(
gallery,{
helpers : {
thumbs : {
width: 75,height: 50
}
},});
});
}
});
fancybox 画廊打开,显示画廊中正确数量的图像,但没有显示任何图像。 Container还是空的,fancybox图片的src还是空的。
我做错了什么?
解决方法
发现图片 url 的键名必须命名为“src”而不是“href”。