Flickity 到达下一张或上一张幻灯片时的事件

Event for when Flickity reaches the next or previous slide

Flickity 有事件绑定。下一张或上一张幻灯片移至时是否有事件?例如 settle event is fired after a slide settles. This does do what I need but the problem here is it also fires if Flickity settles on the same slide, this would happen if you swiped but didn't swipe enough and Flickity settles back where it was. The cellSelect demo 似乎做了很多相同的事情。

在我看来,这样的事情也许可以解释我想要实现的目标:

$carousel.on( 'nextSlideReached', function() {
   console.log( 'Flickity has settled on the next slide' );
});

使用结算事件,我们可以检查我们是否已在新幻灯片上结算:

var selectedIndex = flkty.selectedIndex;

$carousel.on( 'settle', function() {
  if ( flkty.selectedIndex !== selectedIndex ) {

    console.log('settled at new cell', flkty.selectedIndex);
    selectedIndex = flkty.selectedIndex;

    // do stuff

  }
});