简体   繁体   English

将fancybox项分组以获取下一个和上一个功能

[英]Group fancybox items for next and previous functionality

So the fancybox plugin works on my site but only for single images, so I'm not able to scroll between them, or switch with next-prev buttons. 因此,fancybox插件在我的网站上有效,但仅适用于单个图像,因此我无法在它们之间滚动或使用next-prev按钮进行切换。 I know that fancybox needs to see the group to enable this, but I got stuck here and still get only the single images. 我知道fancybox需要查看组才能启用此功能,但是我被困在这里,仍然只获得单个图像。 Here's my jQuery snippet and HTML structure: 这是我的jQuery代码段和HTML结构:

Many thanks for any help. 非常感谢您的帮助。

$('dl.gallery-item').each(function(index) {
    var rel = "group"; // +$(this).attr('id');
    $('.gallery-item a').addClass('fancybox').attr('rel', rel);

});
$('.fancybox').fancybox(); 

<div id="gallery-1" class="gallery galleryid-15 gallery-columns-4 gallery-size-thumbnail">
      <dl class="gallery-item">
            <dt class="gallery-icon landscape">
                <a href="//localhost:3000/path-to-image" class="fancybox" rel="group"><img width="253" height="164" src="path-to-image" class="attachment-thumbnail size-thumbnail" alt=""></a>
            </dt></dl><dl class="gallery-item">
            <dt class="gallery-icon landscape">
                <a href="//localhost:3000/path-to-image" class="fancybox" rel="group"><img width="253" height="164" src="path-to-image" class="attachment-thumbnail size-thumbnail" alt=""></a>
            </dt></dl><dl class="gallery-item">
            <dt class="gallery-icon landscape">
                <a href="//localhost:3000/path-to-image" class="fancybox" rel="group"><img width="253" height="164" src="path-to-image" class="attachment-thumbnail size-thumbnail" alt=""></a>
            </dt>
      </dl>
</div>

Here is your HTML with a working Fancybox implementation: 这是带有有效Fancybox实现的HTML:
https://jsfiddle.net/alan0xd7/z3h8zf65/ https://jsfiddle.net/alan0xd7/z3h8zf65/

This is using the latest Fancybox version 3.0.47 这使用的是最新的Fancybox版本3.0.47

Basically the only change is instead of using rel , it is data-fancybox for groups. 基本上,唯一的变化是代替了rel ,它是组的data-fancybox

If you cannot get it working, edit my fiddle and show what exactly your code looks like. 如果您无法使其正常运行,请编辑我的小提琴并显示您的代码究竟是什么样子。

Hope this helps! 希望这可以帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM