metafizzy / flickity

:leaves: Touch, responsive, flickable carousels
https://flickity.metafizzy.co
7.52k stars 605 forks source link

Is there a way where I can randomize the slide image on each load? #1018

Closed thousandzero closed 4 years ago

thousandzero commented 4 years ago

Test case: https://codepen.io/desandro/pen/azqbop

clarknelson commented 4 years ago

I think you will need to create the gallery with javascript, so you can attach events.

var flkty = new Flickity( '.carousel', {
  on: {
    ready: function() {
      const galleryLength = this.getCellElements().length;
      this.selectCell( Math.floor(galleryLength * Math.random()), true, true );
    }
  }
});

See https://flickity.metafizzy.co/api.html#selectcell for more details.