【问题标题】:jQuery fancybox with thumbnail带有缩略图的 jQuery 花式框
【发布时间】:2017-10-31 10:53:05
【问题描述】:

我正在使用 Magento 1.9.2.4 附带的 fancybox (2.15) 和 elevatezoom (3.0.8) 来缩放主图像并使用画廊的其他图像创建一个 fancybox 画廊。单击主图像时会打开 Fancybox。

我需要的是在fancybox打开时使用缩略图助手来导航缩略图,但问题是我无法以最简单和建议的方式初始化它,比如

$(selector).fancybox({config});

我使用的方式对fancybox 的外观没有影响。

这是我正在使用的代码

js

$(document).ready(function() {
            if($('.thumb-link').size() == 0){
                var ez = $('.gallery-image.visible').first().data('zoom-image');
            }else{
                var ez =  $(".thumb-link");
            }

            $.fancybox({
                'width':400,
                'height': 500,

                helpers : {
                    title   : {
                        type: 'outside'
                    },
                     thumbs : {
                       width    : 50,
                       height   : 50
                    }
                }
            });

            $(".gallery-image.visible").bind("click", function(e) {  
                $.fancybox(ez);
                return false;
            });

        });

.gallery-image.visible 是主图像,.thumb-link 是我的 Html 中的缩略图。

关注其他类似问题using fancybox set height and width

但我实际上在花式框上看不到效果。

在有效调用fancybox配置之前,有没有其他方法可以重新初始化它?

编辑: 实际上我以这种方式更改了我的代码:

var fancyConfig =  {'width' : 200, 'height': 300,...};

            $(".gallery-image.visible").bind("click", function(e) {  
                $.fancybox(ez, fancyConfig);
                return false;
            });

我可以看到一些效果,但没有拇指痕迹....我包含并可以看到用于 fancybox 缩略图助手的正确库。

【问题讨论】:

    标签: javascript jquery magento fancybox elevatezoom


    【解决方案1】:

    我认为这段代码没有做任何事情,我在这里看不到任何选择器或对象集合:

    $.fancybox({
      'width':400,
      'height': 500,
    
      helpers : {
        title   : {
          type: 'outside'
        },
        thumbs : {
          width    : 50,
          height   : 50
        }
      }
    });
    

    我认为您应该将$.fancybox(ez); 替换为$.fancybox.open(ez, {config});

    【讨论】:

    • 是的,您几乎是对的,如果您查看我编辑的代码,您会发现我正在尝试执行您建议的几乎相同的操作(只是颠倒参数的顺序),但我仍然没有拇指的痕迹。
    • 如果你能提供一个 jsfiddle/codepen 演示,那会很有帮助。
    • mmmm 实际上我创建了一个小提琴并且在小提琴中更新的代码似乎可以工作......问题是它在我的服务器中不起作用,并且使用 magento 总是很难理解为什么。 ...这是小提琴jsfiddle.net/4s7hLdyf
    【解决方案2】:

    实际上,我发现使用小提琴中使用的库而不是我在服务器中加载的库,可以使脚本兼容并且可以正常工作。 所以它是这样工作的:

    var fancyConfig =  {
                helpers : {
                    thumbs  : {
                        width   : 50,
                        height  : 50
                    }
                }
            };
            $(".gallery-image").click(function(e) {  
                $.fancybox(ez, fancyConfig);
                return false;
            });
    

    还有fiddle

    $(document).ready(function() {
          if($('.thumb-link').size() == 0){
              var ez = $('.gallery-image.visible').first().data('zoom-image');
          }else{
              var ez =  $(".thumb-link");
          }
    
          var fancyConfig =  {
                  'speedIn' : 1000,
                  'speedOut' : 1000,
                  helpers : {
                      title   : {
                          type: 'outside'
                      },
                      thumbs  : {
                          width   : 50,
                          height  : 50
                      }
                  }
              };
          $(".gallery-image.visible").bind("click", function(e) {  
              $.fancybox(ez, fancyConfig);
              return false;
          });
    
      });
    ul {
        list-style: none;
        margin: 0;
        padding: 0;
    }
    
    .product-image-thumbs li:first-child {
        margin-left: -1px;
    }
    .product-image-thumbs li{
        display: inline-block;
        margin-right: 2%;
    }
    .product-image-thumbs a {
        display: inline-block;
        border: 1px solid #cccccc;
        overflow: hidden;
    }
    .product-image-thumbs a img{
      width: 122px;
      height: 122px;
      overflow: hidden;
    }
    
    .product-image-gallery .gallery-image {
        display: none;
    }
    .product-image-gallery .gallery-image.visible {
        display: block;
    }
    
    .product-img-box .product-image img {
        max-width: 100%;
        max-height: 750px;
        width: 500px;
        max-width: 500px;
        margin: 0px auto;
    }
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
    <link href="https://cdnjs.cloudflare.com/ajax/libs/fancybox/2.1.5/jquery.fancybox.css" rel="stylesheet"/>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/fancybox/2.1.5/jquery.fancybox.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/fancybox/2.1.5/helpers/jquery.fancybox-thumbs.js"></script>
    <link href="https://cdnjs.cloudflare.com/ajax/libs/fancybox/2.1.5/helpers/jquery.fancybox-thumbs.css" rel="stylesheet"/>
    
    <div class="product-img-box">
      <div class="product-image product-image-zoom zoom-available">
          <div class="product-image-gallery">
              <img id="image-main"
                   class="gallery-image visible"
                   src="https://static.pexels.com/photos/111755/pexels-photo-111755.jpeg"
                   alt="custom-alt"
                   title="img-title" 
                    data-zoom-image="https://static.pexels.com/photos/111755/pexels-photo-111755.jpeg" />
    
                  <img id="image-main"
                       class="gallery-image"
                   src="https://static.pexels.com/photos/111755/pexels-photo-111755.jpeg" />
                  <img id="image-0"
                       class="gallery-image"
                       src="https://static.pexels.com/photos/67832/sunrise-sky-blue-sunlight-67832.jpeg" />
                   <img id="image-1"
                       class="gallery-image"
                       src="https://media.istockphoto.com/photos/majestic-sunrise-over-the-mountains-picture-id185067762?k=6&m=185067762&s=612x612&w=0&h=QFGIsuncZGtiLeCQk6aMR14nOUrJNsFmXgpbT7oEU0c=" />
                  <img id="image-2"
                       class="gallery-image" src="https://static.pexels.com/photos/111755/pexels-photo-111755.jpeg" />
    
          </div>
      </div>
    </div>
    
    
    <div class="more-views">
       <ul class="product-image-thumbs">
            <li>
                <a class="thumb-link" title="my-title" rel="fancybox-thumb" data-image-index="2" href="https://static.pexels.com/photos/111755/pexels-photo-111755.jpeg">
                    <img src="https://static.pexels.com/photos/111755/pexels-photo-111755.jpeg" alt="custom-alt" />
                </a>
                <a class="thumb-link" title="my-title" rel="fancybox-thumb" data-image-index="0" href="https://static.pexels.com/photos/67832/sunrise-sky-blue-sunlight-67832.jpeg">
                    <img src="https://static.pexels.com/photos/67832/sunrise-sky-blue-sunlight-67832.jpeg" alt="custom-alt" />
                </a>
                <a class="thumb-link" title="my-title" rel="fancybox-thumb" data-image-index="1" href="https://media.istockphoto.com/photos/majestic-sunrise-over-the-mountains-picture-id185067762?k=6&m=185067762&s=612x612&w=0&h=QFGIsuncZGtiLeCQk6aMR14nOUrJNsFmXgpbT7oEU0c=g">
                    <img src="https://media.istockphoto.com/photos/majestic-sunrise-over-the-mountains-picture-id185067762?k=6&m=185067762&s=612x612&w=0&h=QFGIsuncZGtiLeCQk6aMR14nOUrJNsFmXgpbT7oEU0c=" alt="custom-alt" />
                </a>
            </li>
        </ul>
    </div>

    【讨论】:

      猜你喜欢
      • 2018-01-24
      • 1970-01-01
      • 2014-05-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-04-15
      • 1970-01-01
      相关资源
      最近更新 更多