DyderSnyper
DyderSnyper

Reputation: 1

Retrieve number of current slide using slideNumber Reveal.js

I need your help about Reveal.js.

Anyone can explain me how to retrieve the number of my currentslide, and add it into variable ?

I need to add an event on my slide 4.

Thx for the support

Upvotes: 0

Views: 2210

Answers (3)

sr.Xur
sr.Xur

Reputation: 11

I do this to get the indice of the SLide:

 Reveal.addEventListener('slidechanged', function (evt) {
        ind = Reveal.getIndices().h
        if (ind === 0) {
            ......
        }
        if (ind === 1) {
            .....
        }
 });

Upvotes: 0

Sethos II
Sethos II

Reputation: 176

You can get the indices of the current slide with Reveal.getIndices(). It returns an object with three properties:

  • h: horizontal index of the slide
  • v: vertical index of the slide
  • f: Index of a fragment within the slide

Now you can compare the current index with the index of the slide you want.

Upvotes: 2

Samuli Hakoniemi
Samuli Hakoniemi

Reputation: 19049

Is this what you meant?

Reveal.addEventListener('slidechanged', function(evt) {
  if (evt.currentSlide === 4) {
    // Do your stuff
  }
});

You can always store currentSlide somewhere and then retrieve it later if your action requires it to be done in the middle of the presentation, not on slidechanged.

Upvotes: 0

Related Questions