javascriptwordpresslightgallery

How to add settings to lightGallery


Im using lightGallery to open a lightbox of images using the solution below, which was found here: https://stackoverflow.com/a/54764289/1390648

Where can I add the settings from the lightGallery docs to the code below to control the mode, speed, and other settings?

Each time I try to add them in, it breaks the lightGallery from opening.

function initLightGallery() {
    lightGallery(document.getElementById('lightgallery'));
    $("#magic_start").on("click", () => {
        $("#lightgallery :first-child > img").trigger("click");
    });
}
initLightGallery();

Solution

  • Replace your second line

    lightGallery(document.getElementById('lightgallery'));
    

    by

    lightGallery(document.getElementById('lightgallery'), {
        speed: 500,
        mode: 'fade',
        ...Other settings
    });
    

    It is right there in the docs ;-)

    -> https://www.lightgalleryjs.com/docs/settings/