【问题标题】:Issue with jquery zoom and bootstrap multi item carouseljquery缩放和引导多项目轮播问题
【发布时间】:2018-05-02 21:09:16
【问题描述】:

我正在开发一个需要缩放功能的产品轮播。 轮播是引导程序,定制为每张幻灯片显示两个项目。 然后,我使用 jQuery zoom 进行产品缩放,但对其进行了一些自定义,因此它会在单击时打开一个模态,然后进行缩放。

这是我的轮播代码

<div id="Carousel" class="carousel multi-item-carousel slide small--hide">
  <div class="grid grid--no-gutters">
<div class="carousel-inner">
    {% assign variable = 0 %}
      {% for image in product.images %}
   <div class="item">
   <div class="grid__item one-half carousel-padding">
       <style>
  .imgModal_{{ image.id }} {
    width: 100%;
    margin: 0 auto;
    display: none;
  }
   </style>
           <img class="{{ image.id }}_test" src="{{ image.src | img_url: 'master' }}" alt="{{ image.alt | escape }}" class="product-zoom"/>
           <div class="imgModal_{{ image.id }} imgmodal">
             <div class="img-zoom-container">
               <span class="close"></span>
             <img src="{{ image.src | img_url: 'master'  }}" alt="{{ image.alt | escape }}" class="image-zoom">
             <script>
               ;(function(window, $, undefined) {
                 $('.{{ image.id }}_test').on('click', function(){
                  $(this).next('.imgModal_{{ image.id }}').css('display', 'block');
                });

                $('.imgModal_{{ image.id }}').click(function(){
                  $('.imgModal_{{ image.id }}').css('display', 'none');
                });
              })(window, jQuery);
             </script>
           </div>
            </div>
   </div>
 </div>
     {% endfor %}
</div>
<a data-slide="prev" href="#Carousel" class="left carousel-control">{% include 'carousel-left'%}</a>
    <a data-slide="next" href="#Carousel" class="right carousel-control">{% include 'carousel-right'%}</a>
</div>
</div>

还有多项目轮播的 JS:

<script>
$( document ).ready(function() {
$(".carousel-inner div:first").addClass("active");
});
// Instantiate the Bootstrap carousel
$('.multi-item-carousel').carousel({
  interval: false
});

// for every slide in carousel, copy the next slide's item in the slide.
// Do the same for the next, next item.
$('.multi-item-carousel .item').each(function(){
  var next = $(this).next();
  if (!next.length) {
    next = $(this).siblings(':first');
  }
  next.children(':first-child').clone().appendTo($(this));

});
</script>

我现在的问题是,当它为多项目轮播克隆图像时,模式的点击事件对克隆的项目不起作用。我最初将{{ image.id }}_test 设置为 ID,所以认为这可能是问题,但在将其更改为类之后它仍然无法正常工作。

关于如何解决这个问题的任何想法?

【问题讨论】:

    标签: javascript jquery


    【解决方案1】:

    我实际上只是自己修复了它,以防万一它对任何人有帮助,问题是点击事件在克隆中丢失了,所以只需要添加

    next.children(':first-child').clone(true,true).appendTo($(this));
    

    到我的克隆函数。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-07-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多