2

Is there an event that I can listen to, when Flickity has finished initialization?

When initializing with JavaScript, I can trigger an event by myself, but by using this setup I have no clue.

Initialize with HTML
http://flickity.metafizzy.co/#initialize-with-html

<div data-flickity='{ … }'>
  …
</div>

Currently, I am checking if Flickity has generated it's DOM elements, but that is not very elegant. :-)

Mario
  • 8,253
  • 2
  • 14
  • 29

1 Answers1

1

You can try this:

Flickity.prototype.on( 'activate',function(){ alert("active")});

Flickity.prototype.on( 'activate',function(){
alert("active")});
/* external css: flickity.css */

* { box-sizing: border-box; }

body { font-family: sans-serif; }

.carousel {
  background: #EEE;
}

.carousel-cell {
  width: 100%;
  height: 200px;
  margin-right: 10px;
  background: #8C8;
  border-radius: 5px;
  counter-increment: gallery-cell;
}

/* cell number */
.carousel-cell:before {
  display: block;
  text-align: center;
  content: counter(gallery-cell);
  line-height: 200px;
  font-size: 80px;
  color: white;
}
<script src="https://npmcdn.com/flickity@2/dist/flickity.pkgd.js"></script>
<!-- Flickity HTML init -->
<div class="carousel" id="carousel" data-flickity>
  <div class="carousel-cell"></div>
  <div class="carousel-cell"></div>
  <div class="carousel-cell"></div>
  <div class="carousel-cell"></div>
  <div class="carousel-cell"></div>
</div>
Claytronicon
  • 1,437
  • 13
  • 14