I am using slick slider combined with sachinchoolur lightGallery.
I am running multiple sliders and I want each lightgallery to be related to its relative slider.
Which currently works, but the issue I am having is that lightgallery is getting slick sliders clones.
Normally I can get round this problem by using infinite: false;
in slick, but in this case I really need my sliders to be infinite: true;
.
I cannot get my head round this, is there a work around to this problem?
So only the visible slides, not clones, render into the lightgallery.
Here is a fiddle for easier debugging. https://jsfiddle.net/joshmoto/jmvg5c93/
// init slick slider
$('.slick').slick({
dots: true,
infinite: true,
speed: 300,
slidesToShow: 1,
adaptiveHeight: true
});
// slick light gallery
$('.slick').lightGallery({
selector: '.lightgallery',
//selectWithin: '.slick-slide:not(.slick-cloned)'
});
FIGURE {
margin: 0;
width: 300px !important;
display: block !important;
}
IMG {
width: 100%;
}
.slick {
width: 300px;
margin: 0 auto 60px !important;
}
PRE {
text-align: center;
margin: 15px 0;
}
<pre>4 Space Photos - lightgallery shows 9</pre>
<div class="slick">
<figure>
<a href="https://i.imgur.com/q5Y5RCH.png" class="lightgallery">
<img src="https://i.imgur.com/q5Y5RCH.png" alt="" />
</a>
</figure>
<figure>
<a href="https://i.imgur.com/8HjXPXD.png" class="lightgallery">
<img src="https://i.imgur.com/8HjXPXD.png" alt="" />
</a>
</figure>
<figure>
<a href="https://i.imgur.com/vUDcfcy.png" class="lightgallery">
<img src="https://i.imgur.com/vUDcfcy.png" alt="" />
</a>
</figure>
<figure>
<a href="https://i.imgur.com/okTDHas.png" class="lightgallery">
<img src="https://i.imgur.com/okTDHas.png" alt="" />
</a>
</figure>
</div>
<pre>3 Sea Photos - lightgallery shows 7</pre>
<div class="slick">
<figure>
<a href="https://i.imgur.com/x7ZYW4i.png" class="lightgallery">
<img src="https://i.imgur.com/x7ZYW4i.png" alt="" />
</a>
</figure>
<figure>
<a href="https://i.imgur.com/EYTCssm.png" class="lightgallery">
<img src="https://i.imgur.com/EYTCssm.png" alt="" />
</a>
</figure>
<figure>
<a href="https://i.imgur.com/3sAFPmL.png" class="lightgallery">
<img src="https://i.imgur.com/3sAFPmL.png" alt="" />
</a>
</figure>
</div>
<pre>5 Land Photos - lightgallery shows 11</pre>
<div class="slick">
<figure>
<a href="https://i.imgur.com/IqLrd0o.png" class="lightgallery">
<img src="https://i.imgur.com/IqLrd0o.png" alt="" />
</a>
</figure>
<figure>
<a href="https://i.imgur.com/6JplNl6.png" class="lightgallery">
<img src="https://i.imgur.com/6JplNl6.png" alt="" />
</a>
</figure>
<figure>
<a href="https://i.imgur.com/6X5GKWJ.png" class="lightgallery">
<img src="https://i.imgur.com/6X5GKWJ.png" alt="" />
</a>
</figure>
<figure>
<a href="https://i.imgur.com/SefTwI1.png" class="lightgallery">
<img src="https://i.imgur.com/SefTwI1.png" alt="" />
</a>
</figure>
<figure>
<a href="https://i.imgur.com/qBmDrTU.png" class="lightgallery">
<img src="https://i.imgur.com/qBmDrTU.png" alt="" />
</a>
</figure>
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/lightgallery/1.7.0/css/lightgallery.min.css" rel="stylesheet"/>
<script src="https://cdnjs.cloudflare.com/ajax/libs/lightgallery/1.7.0/js/lightgallery-all.min.js"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/slick-carousel/1.9.0/slick-theme.min.css" rel="stylesheet"/>
<link href="https://cdnjs.cloudflare.com/ajax/libs/slick-carousel/1.9.0/slick.min.css" rel="stylesheet"/>
<script src="https://cdnjs.cloudflare.com/ajax/libs/slick-carousel/1.9.0/slick.min.js"></script>
I just figured it out...
// slick light gallery
$('.slick').lightGallery({
selector: '.slick-slide:not(.slick-cloned) .lightgallery',
});
See fiddle https://jsfiddle.net/joshmoto/u5mh3a8x/