3

I am using

      var allslides = document.querySelector(".lazy");
        for (var i = allslides.children.length; i >= 0; i--) {
          allslides.appendChild(allslides.children[Math.random() * i | 0]);
        };

to randomize the slide order in Slick carousal (image slider).

Here ".lazy" is:

<section class="lazy slider" data-sizes="50vw">
  <div><img src="1.png"/</div>
  <div><img src="2.png"/</div>
  <div><img src="3.png"/</div>
  <div><img src="4.png"/</div>
</section>

All is fine except a blank slide (or a white gap) gets inserted. Just can't get rid of it. Any clues or cues?

Richard Dallaway
  • 4,250
  • 1
  • 28
  • 39

1 Answers1

7

You don't really need to manipulate the DOM at all. Simply hook into the goto method and randomly navigate to a different slide.

This is one of many possible implementations:

var total = $('.slick-slideshow img').length, // get the number of slides
    rand = Math.floor( Math.random() * total ); // random number

$('.slick-slideshow').slick({
    autoplay: true,
    autoplaySpeed: 7000,
    arrows: false,
    fade: true,
    slide: "img",
    pauseOnHover: false
})
.slickGoTo(rand); //navigate to random slide

You can learn more in this discussion: https://github.com/kenwheeler/slick/issues/359

Orlandster
  • 4,706
  • 2
  • 30
  • 45