1

您好,我正在尝试在 jquery 灯箱插件http://leandrovieira.com/projects/jquery/lightbox/中为图片库创建循环。(当它到达最后一张图像时,显示第一张图像的下一个按钮,或者当它显示第一张图像时,显示最后一张图像的上一个按钮)到目前为止,我发现我需要更改这些行:

        // Show the prev button, if not the first image in set
        if ( settings.activeImage != 0 ) {
            if ( settings.fixedNavigation ) {
                $('#lightbox-nav-btnPrev').css({ 'background' : 'url(' + settings.imageBtnPrev + ') left 15% no-repeat' })
                    .unbind()
                    .bind('click',function() {
                        settings.activeImage = settings.activeImage - 1;
                        _set_image_to_view();
                        return false;
                    });
            } else {
                // Show the images button for Next buttons
                $('#lightbox-nav-btnPrev').unbind().hover(function() {
                    $(this).css({ 'background' : 'url(' + settings.imageBtnPrev + ') left 15% no-repeat' });
                },function() {
                    $(this).css({ 'background' : 'transparent url(' + settings.imageBlank + ') no-repeat' });
                }).show().bind('click',function() {
                    settings.activeImage = settings.activeImage - 1;
                    _set_image_to_view();
                    return false;
                });
            }
        }

        // Show the next button, if not the last image in set
        if ( settings.activeImage != ( settings.imageArray.length -1 ) ) {
            if ( settings.fixedNavigation ) {
                $('#lightbox-nav-btnNext').css({ 'background' : 'url(' + settings.imageBtnNext + ') right 15% no-repeat' })
                    .unbind()
                    .bind('click',function() {
                        settings.activeImage = settings.activeImage + 1;
                        _set_image_to_view();
                        return false;
                    });
            } else {
                // Show the images button for Next buttons
                $('#lightbox-nav-btnNext').unbind().hover(function() {
                    $(this).css({ 'background' : 'url(' + settings.imageBtnNext + ') right 15% no-repeat' });
                },function() {
                    $(this).css({ 'background' : 'transparent url(' + settings.imageBlank + ') no-repeat' });
                }).show().bind('click',function() {
                    settings.activeImage = settings.activeImage + 1;
                    _set_image_to_view();
                    return false;
                });
            }
        }

我在 jquery 方面的知识是基本的,所以也许有人可以帮忙?

4

2 回答 2

0

我不确定灯箱是否支持循环。顺便说一句,您可以使用两种方法来做同样的事情。

方法一:使用Fancy Box 插件

在此您的图像也将在弹出窗口中打开,并且它还支持循环,如您所愿。它是高度可定制的。

方法二:使用Jquery Cycle Plugin和 lightbox 这个插件支持循环功能。

对于此类实现,我更喜欢方法 1,但如果您必须使用 lightbox,您可以使用方法 2,而不是编写可能包含错误的自己的代码。

谢谢

于 2012-09-11T05:41:11.767 回答
0

对于弹出循环,magnifix 以这种方式弹出:

for (i = 1; i <= 2; i++) {

  console.log(i);

  $('.popup-gallery' + i).magnificPopup({
    delegate: 'a',
    type: 'image',
    tLoading: 'Loading image #%curr%...',
    mainClass: 'mfp-img-mobile',
    gallery: {
      enabled: true,
      navigateByImgClick: true,
      preload: [0, 1] // Will preload 0 - before current, and 1 after the current image
    },
    image: {
      tError: '<a href="%url%">The image #%curr%</a> could not be loaded.',
      titleSrc: function(item) {
        return item.el.attr('title') + '<small>by PNG City Builder</small>';
      }
    }
  });

}

于 2019-06-22T15:48:24.067 回答