Задать вопрос
Ответы пользователя по тегу JavaScript
  • Как в Fancybox 3 сбросить значение index в $.fancybox.open?

    kepkame
    @kepkame Автор вопроса
    Получил ответ на другом форуме. Настройка afterClose не понадобилась, я совсем не в ту сторону копал.

    var fancyElements = jQuery.map(jQuery('.product-gallery__item a'), function(el) {
          return{
          src: el.href,
          caption: el.title
         }
        });
    
    jQuery(".product-gallery__wrapper").slick({
      slidesToShow: 1,
      slidesToScroll: 1,
      infinite: false,
      centerMode: false,
      focusOnSelect: true,
      asNavFor: '.gallery-thambnails'
    });
    
    // Highlight thumbnail if large image is the same
    jQuery(".gallery-thambnails").on("afterChange", function(event, slick, currentSlide, nextSlide) {
      // remove all active class
      jQuery(".gallery-thambnails .slick-slide").removeClass("slick-current");
      // set active class for current slide
      jQuery(".gallery-thambnails .slick-slide:not(.slick-cloned)").eq(currentSlide).addClass("slick-current");
      jQuery("#wcOpenFullPhoto").data("order", currentSlide);
    });
    
    jQuery(".gallery-thambnails").slick({
      slidesToShow: 4,
      slidesToScroll: 1,
      infinite: false,
      dots: false,
      centerMode: false,
      focusOnSelect: true,
      asNavFor: '.product-gallery__wrapper'
    });
    
    jQuery('#wcOpenFullPhoto').on('click', function(e) {
      e.preventDefault();
      jQuery.fancybox.open(
        fancyElements, {
          // Custom options
          loop: false,
        },
        jQuery("#wcOpenFullPhoto").data("order")  // Start gallery from selected index
      );
    });
    Ответ написан
    Комментировать