See the parameters passed to the events:
And work with these values in some way.
Here is one possible solution:
You might want to make it more flexible to cover first and last slide index - independent of the number of slides.
Something like this: