Jump to slide #n

2.9k Views Asked by At

How can I interactively jump to a specific slide?

Programmatically, I can use Reveal.slide( indexh, indexv, indexf).

For instance, in S5, I can enter the slide number and then press Enter.

5

There are 5 best solutions below

1
On

For what it's worth, I compiled a quick script that allows you to, e.g., jump to slide 17.3 by pressing 1,7,enter,3,enter and then the slide jumps.

<script type="text/javascript">
    const key_presses = [];
    const append = function(arr, item) {
        const idx = arr.length;
        arr.splice( idx, 0, item );
    }
    const pop = function(arr) {
        const l = arr.length;
        if (l === 0){
            return false;
        }
        return arr.splice(l-1,l)[0];
    };
    const go_to_slide = function(evt) {
        if (evt.keyCode === 13) { // enter
            if (key_presses.indexOf('enter') !== -1){
                let val = pop(key_presses);
                let size = 1;
                let v = 0;
                while(val !== 'enter') {
                    v = v + size *  val;
                    size = size * 10;
                    val = pop(key_presses)
                }

                let h = 0;
                size = 1;
                val = pop(key_presses);
                while(val !== false) {
                    h = h + size * val;
                    size = size * 10;
                    val = pop(key_presses);
                }
                Reveal.slide(h-1, v-1);
            } else {
                append(key_presses, 'enter');
            }
        } else {
            append(key_presses, parseInt(evt.key, 10));
        }
    };
</script>
<script>
    Reveal.initialize({
        slideNumber: true,
        keyboard: {
            13: go_to_slide,
            48: go_to_slide,
            49: go_to_slide,
            50: go_to_slide,
            51: go_to_slide,
            52: go_to_slide,
            53: go_to_slide,
            54: go_to_slide,
            55: go_to_slide,
            56: go_to_slide,
            57: go_to_slide,
        }
}
</script>
0
On

I did this to set the E key to jump to the last slide and the J key to prompt me for the slide to go to:

<script>
 Reveal.initialize({
     keyboard: {
         69: () => { Reveal.slide(Reveal.getSlides().length-1) },
         74: () => { Reveal.slide(prompt("Slide no")-1) }
     }
 });
</script>

Or actually, since I use org-reveal, what I actually did was put this in my ORG file:

#+REVEAL_INIT_OPTIONS: keyboard: {69:()=>{Reveal.slide(Reveal.getSlides().length-1)},74:()=>{Reveal.slide(prompt("Slide no")-1)}}
0
On

For the latest version of Reveal, I used this to get it to work

Reveal.initialize({

    keyboard: {
        56: function() { Reveal.slide( 8 ) },
    },
});
0
On

Just one note to the code of Amanda. Where can I put it? I didn't know: It's just in the index.html, at the end:

        Reveal.initialize({
            controls: false,
            progress: true,
            history: true,
            center: true,
            keyboard: {
              13: 'next', // go to the next slide when the ENTER key is pressed
              27: function() {}, // do something custom when ESC is pressed
              32: null // don't do anything when SPACE is pressed (i.e. disable a reveal.js default binding)
            },
            theme: Reveal.getQueryHash()
1
On

There are succinct instructions for overriding the default keybindings in the Reveal.js Documentation. They say this:

Reveal.configure({
  keyboard: {
    13: 'next', // go to the next slide when the ENTER key is pressed
    27: function() {}, // do something custom when ESC is pressed
    32: null // don't do anything when SPACE is pressed (i.e. disable a reveal.js default binding)
  }
}); 

Keycodes for numbers 1-9 are 49-57 (0 is 48), so my read of the reveal.js event.keycode switch suggests you want something like:

Reveal.configure({
  keyboard: {
    56: slide( 8 ), 
  }
}); 

I'm not much of a jQuery whiz, but writing a function that notes any additional digits and waits for enter before jumping to slide n seems like a sort of advanced beginner level challenge (and a question that plenty of folks here could help you with). Question: what should happen if I type a non-number before I get to enter? What does 5qenter do?