Fancybox:动态更改 data-fancybox-group

发布于 2025-01-01 05:06:39 字数 1009 浏览 2 评论 0原文

我有一个巨大的图像库,带有一个过滤系统,该系统仅突出显示我从过滤器中选择的图像。因此,当我在画廊上设置过滤器时,我会动态更改 data-fancybox-group 以仅在我过滤的图像之间创建画廊,但 Fancybox 似乎不喜欢它......

所以当我切换过滤器时尝试在过滤器更改后单击图像,fancybox 根本不起作用。有人对此有线索吗?

谢谢!

这是 Fancybox 的代码:

$(".fancybox").fancybox({
 openEffect : 'fade',
 closeEffect : 'fade',
 prevEffect : 'fade',
 nextEffect : 'fade',
 prevSpeed : 'normal',
 nextSpeed : 'normal',
 arrows : true,
 closeBtn : true
});

这是我的过滤器代码:

$(".menu-gallery li a").click(function (){

//My filter menu have a id's
var thisID = this.id;

//Loop in the gallery to show or hide the filter image with the selected filter
$(".list-item li div").each(function(){
    if ( $(this).hasClass(thisID) ) {
        $(this).removeClass('hide');
        //Change the data group on the fly to make a gallery only with the selected filter image
        $("a", this).attr('data-fancybox-group',thisID);
    } else {
        $(this).addClass('hide');        
    }

});

});

I have a huge gallery of images with a filter system that's highlight only images that I choose from the filter. So when a I set a filter on my gallery I change dynamically the data-fancybox-group to make a gallery only between the image that I filter but Fancybox seem to don't like it...

So when i switched the filter when I try to click on a images after a filter change the fancybox dosen't work at all. Anybody have a clue on that?

Thanks!

Here is the code of Fancybox :

$(".fancybox").fancybox({
 openEffect : 'fade',
 closeEffect : 'fade',
 prevEffect : 'fade',
 nextEffect : 'fade',
 prevSpeed : 'normal',
 nextSpeed : 'normal',
 arrows : true,
 closeBtn : true
});

Here my filter code :

$(".menu-gallery li a").click(function (){

//My filter menu have a id's
var thisID = this.id;

//Loop in the gallery to show or hide the filter image with the selected filter
$(".list-item li div").each(function(){
    if ( $(this).hasClass(thisID) ) {
        $(this).removeClass('hide');
        //Change the data group on the fly to make a gallery only with the selected filter image
        $("a", this).attr('data-fancybox-group',thisID);
    } else {
        $(this).addClass('hide');        
    }

});

});

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文