Search code examples
javascriptlightbox2

How to know when last image reached in lightbox2


Using jQuery lightbox2, is there a way to know when the last image is reached? In the options, wrapAround is listed, but that only provides a way to loop back to the start.

I'm interested in calling a function when the last image is reached, is this possible?


Solution

  • Currently lightbox v2 doesn't have an API for events. You should do it manually. Either by tracking:

    $('body').on('click', '.lb-next', function() {
        //Get the current visible image and its position
    });
    

    Respectively you can track .lb-prev.

    Or using a plugin for tracking changing styles and check wether the image that is going to be shown is the last.