How to trigger an event when a certain slide is active?

Hi,
when I scroll through the slides of an ion-slider without using buttons,ì but on the screen of the phone, is there an event that can be raised when a certain slide is shown?

For example, I’d like to print an alert when the 3rd slide is shown, but at this moment I don’t know when the user is on the 3rd slide.

<ion-slides> has a zillion events. I would start by listening to ionSlideDidChange, seeing if we’re on slide 3, and then going to town.

1 Like

Hi @rapropos you’ re right, I did see those events but I was deceived by the fact that they work only when you use the app on a real device.
In debug mode (ionic serve -lcs) the event ionSlideDidChange, for example, was never raised.
So yes I’ve used this event in this way:

<ion-slides pager="true" [options]="slideOpts" (ionSlideDidChange)="sliderChanges()">

  sliderChanges() {
    const context = this;
    this.slides.getActiveIndex().then(index => {
      console.log('@@@@ sliderChanges: index:', index);

      if (index === 3) {
...
      }

    });
  }

Thank you
cld

2 Likes