Search code examples
reveal.js

In reveal.js, is there a standard way to make left-click advance to the next slide?


In Powerpoint, clicking the left mouse button advances to the next slide. In reveal.js, it is done using the keyboard. Is it possible to configure reveal.js to advance to the next slide also when clicking the mouse button?


Solution

  • It looks like you can add a click event to the entire slide and and check the button for the event.

    window.addEventListener("mousedown", handleClick, false);
    window.addEventListener("contextmenu", function(e) { e.preventDefault(); }, false);
    
    function handleClick(e) {
        e.preventDefault();
        if(e.button === 0) Reveal.next(); 
        if(e.button === 2) Reveal.prev(); 
    }
    

    If you're worried about links on the page not being clickable you can check the target of the event. If it's a link, don't proceed to the next slide.

    This site could be useful and has a more in depth explanation. It's where the above code is from.