D
D
Danil Fliginskiy2020-07-31 16:29:14
JavaScript
Danil Fliginskiy, 2020-07-31 16:29:14

How to open the desired slide in slick-slider?

I have a gallery of 6 pictures. Clicking on the image opens a large slider. But I need to make sure that the slider opens immediately from the desired image. For example, I clicked on the 3rd picture, the slider opened, but the 3rd slide was immediately active. And so on...
Here's what I wrote, but this script does not work. Slide 3 doesn't open...

//gallery carousel

      $('.gallery__img').each(function(i){
        $(this).on('click', function(){
          $('.overlay, #galleryPhoto').fadeIn('slow');
          $('body').css({
            'overflow':'hidden'
          });
          $('.carousel_gallery').slick('setPosition');
        });
      });

      const galleryImg          = document.querySelectorAll('.gallery__img'),
            carouselGalleryItem = document.querySelectorAll('.carousel_gallery__item');

      galleryImg.forEach((item, i) => {

        item.addEventListener('click', () => {

          carouselGalleryItem.forEach(elem => {

            elem.classList.remove('slick-active');
            elem[i].classList.add('slick-active');

          });

        });

      });

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