M
M
Maxim2018-01-31 23:00:03
JavaScript
Maxim, 2018-01-31 23:00:03

How to reinitialize Swiper inside Magnific Popup?

There is a gallery of modal windows Magnific Popup. You can open them all separately, or you can open one and flip inside.

$('.open-example').magnificPopup({
            mainClass: 'mfp-fade',
            type: 'inline',
            gallery:{
                enabled: true,
                arrows: false
            },
            callbacks: {
                beforeOpen: function(){
                    $(window).trigger('resize');
                }
            }
        });

        $('.prev-proj').on('click', function(e) {
            e.preventDefault();
            $.magnificPopup.instance.prev();
            return false;
        });

        $('.next-proj').on('click', function(e) {
            e.preventDefault();
            $.magnificPopup.instance.next();
            return false;
        });


Inside each slide is a slider:
var galleryTop = new Swiper('.gallery-top', {

        loop:true,
        loopedSlides: 6,
        navigation: {
            nextEl: '.swiper-button-next',
            prevEl: '.swiper-button-prev',
        },
    });
    var galleryThumbs = new Swiper('.gallery-thumbs', {
        spaceBetween: 20,
        loop:true,
        loopedSlides: 6,
        slidesPerView: 3,
        touchRatio: 0.2,
        slideToClickedSlide: true,
    });
    galleryTop[0].controller.control = galleryThumbs;
    galleryThumbs[1].controller.control = galleryTop;

Well, when switching magnifica slides, the internal slider breaks. How to be? I sin on these lines, but I'm not sure
galleryTop[0].controller.control = galleryThumbs;
galleryThumbs[1].controller.control = galleryTop;

It's just that if you remove [0] and [1], it gives "Cannot set property 'control' of undefined".

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question