简体   繁体   English

jQuery Zoom和Bootstrap Multi Item Carousel的问题

[英]Issue with jquery zoom and bootstrap multi item carousel

I'm working on a product carousel which needs a zoom functionality. 我正在研究需要缩放功能的产品轮播。 The carousel is bootstrap, customised to display two items per slide. 轮播是自举的,自定义为每个幻灯片显示两个项目。 I'm then using jQuery zoom for the product zoom but customised that a bit so it opens a modal on click and then does the zoom. 然后,我使用jQuery zoom进行产品缩放,但对它进行了自定义,因此在单击时打开一个模态,然后进行缩放。

This is my code for the carousel 这是我的轮播代码

<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>

And the JS for the multi item carousel: 以及用于多项目轮播的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>

My problem now is that when it clones the images for the mutli item carousel the click event for the modal isn't working on the cloned item. 我现在的问题是,当它为多个项目轮播克隆图像时,模态的click事件在克隆的项目上不起​​作用。 I originally had the {{ image.id }}_test set as IDs so thought that might be the issue but after changing it to a class instead it's still not working. 我最初将{{ image.id }}_test设置为ID,以为可能是问题所在,但将其更改为类后,仍然无法使用。

Any ideas on how to fix this? 有想法该怎么解决这个吗?

I've actually just fixed it myself so in case it helps anybody the issue was that the click event got lost in the clone so just had to add 我实际上只是自己修复了它,以防万一它对任何人都有帮助,因为问题是单击事件在克隆中丢失了,因此只需添加

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

to my clone function. 我的克隆功能。

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

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