Javascript 通过手动链接打开多个Fancybox库
我已尝试转换中提供的解决方案,以便将其应用于多个库,但无法使其正常运行 我有几个具有以下属性的链接:Javascript 通过手动链接打开多个Fancybox库,javascript,jquery,fancybox,fancybox-2,Javascript,Jquery,Fancybox,Fancybox 2,我已尝试转换中提供的解决方案,以便将其应用于多个库,但无法使其正常运行 我有几个具有以下属性的链接: <a href="#" class="open-album" data-open-id="album-1">Album 1</a> <a href="#" class="open-album" data-open-id="album-2">Album 2</a> 如您所见,目标是从专辑标题中获取数据打开id,并使用它打开第一个Fancybox项目
<a href="#" class="open-album" data-open-id="album-1">Album 1</a>
<a href="#" class="open-album" data-open-id="album-2">Album 2</a>
如您所见,目标是从专辑标题中获取数据打开id
,并使用它打开第一个Fancybox项目,其值为rel
属性。唉,它不起作用。对可能出现的问题有什么想法吗?非常感谢您的帮助
提前谢谢 我假设您正在将选择器
.image show
绑定到fancybox,是吗
$(".image-show").fancybox();
如果是这样的话,代码的问题是应该使用$(this.element)
,但是由于您使用的是常规的jQuery方法(.click()
),那么您应该像$(this)
一样引用当前元素
请参见谢谢!你真棒!
<a href="#" class="image-show" rel="album-2"><img src="#" /></a>
<a href="#" class="image-show" rel="album-2"><img src="#" /></a>
<a href="#" class="image-show" rel="album-2"><img src="#" /></a>
$('.open-album').click(function(e) {
var el, id = $(this.element).data('open-id');
if(id){
el = $('.image-show[rel=' + id + ']:eq(0)');
e.preventDefault();
el.click();
}
});
$(".image-show").fancybox();
$('.open-album').click(function(e) {
var el, id = $(this).data('open-id');
if(id){
el = $('.image-show[rel=' + id + ']:eq(0)');
e.preventDefault();
el.click();
}
});