简体   繁体   English

Fancybox 无法处理由 ajax 调用加载的内容

[英]Fancybox not working on content loaded by ajax call

There is a quickshop implemented by using the fancybox on the collection pages and now the load more functionality has been implemented which is working fine and on scroll the products form next page is successfully appended.有一个通过在集合页面上使用fancybox 实现的快速商店,现在已经实现了加载更多功能,该功能运行良好,并且在滚动产品表单下一页已成功附加。

The issues is the new products which is getting embedded on those quickview not working.问题是嵌入在那些无法正常工作的快速视图中的新产品。

the code is below代码在下面

$(".quick_shop").fancybox({
        width: modal_width,
        height: 'auto',
        autoSize: false,
        padding: [20, 20, 20, 20],
        afterShow: function(e) {
          var selector = $('.fancybox-opened').find('.selector-wrapper select');
          selector.trigger('change');
        },
        beforeShow: function(e) {

          var $gallery = $('.' + $(this.element).data('gallery'));
          var $product = $(this.element).data("fancybox-href");
          var thumbnailPosition = $gallery.parents('.product_section').data('thumbnail');
          var slideshowAnimation = $gallery.parents('.product_section').data('slideshow-animation');
          var slideshowSpeed = $gallery.parents('.product_section').data('slideshow-speed');

          $gallery.flexslider({
            startAt: parseInt($('.featured_image', $(this)).data('index'), 10),
            touch: true,
            pauseOnHover: true,
            controlNav: thumbnailPosition == "no-thumbnails" ? false : "thumbnails",
            directionNav: thumbnailPosition == "no-thumbnails" ? true : false,
            animation: slideshowAnimation == 'none' || slideshowAnimation == 'zoom' ? 'fade' : slideshowAnimation,
            slideshow: slideshowAnimation == 'none' || slideshowAnimation == 'zoom' ? false : true,
            slideshowSpeed: slideshowSpeed ? slideshowSpeed*1000 : 10*1000,
            start: function(slider){
              slider.resize();
            }
          });

          if (slideshowAnimation == 'slide'){
            if($gallery.data("index") == 0) { $('.flex-direction-nav', $gallery).hide() }
          } else {
            if($gallery.length == 1) { $('.flex-direction-nav', $gallery).hide() }
          }
        }
      });

How can I make this function works on the ajax loaded content?我怎样才能让这个函数在 ajax 加载的内容上工作?

You are changing content of your page and that means you are creating fresh DOM elements that have no click event attached to them.您正在更改页面的内容,这意味着您正在创建没有附加点击事件的新 DOM 元素。 So, either call $('your selector').fancybox() each time you change contents or use selector option to bind click event (that starts fancybox) to the selector (you can find example in the docs - https://fancyapps.com/fancybox/3/docs/#usage )因此,每次更改内容时都调用$('your selector').fancybox()或使用selector选项将单击事件(启动fancybox)绑定到选择器(您可以在文档中找到示例 - https://fancyapps .com/fancybox/3/docs/#usage )

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

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