felixhagspiel / jsOnlyLightbox

Responsive Lightbox in plain JS. No need for jQuery.
MIT License
157 stars 49 forks source link

Add play to create a slideshow? #34

Closed pwFoo closed 7 years ago

pwFoo commented 8 years ago

A slideshow feature with play button would be great.

felixhagspiel commented 7 years ago

@pwFoo I found that users are more likely to watch galleries in their own speed rather than in predefined slideshows, thats why I didnt implement it yet. But actually this is pretty simple to do it yourself:

    var slideshowTimer = null;
    var lightbox = new Lightbox();
    function startSlideShow(){
        slideshowTimer = window.setInterval(function(){
            lightbox.next();
        },5000); // time in milliseconds
    };
    function stopSlideShow(){
        window.clearInterval(slideshowTimer);
    };

    lightbox.load({
        onopen: function (image) {
            startSlideShow();
        },
        onclose: function (image) {
            stopSlideShow();
        }
    });

And to add a play / pause button just create your own button (be sure to only display it when the box is open) and on button-click call startSlideShow() or stopSlideShow.