How to add additional caption in fancybox


Here’s my setup for the fancybox:

Fancybox.bind('[data-fancybox="media"]', {
                mouseWheel: true,
                modal: true,
                Toolbar: {
                    display: [
                        id: "counter",
                        position: "center",
                on: {
                    initLayout: (fancybox) => {

                    // Create left column
                    const $leftCol = document.createElement("div");

                    while (fancybox.$container.firstChild) {

                    // Create right column
                    const $rightCol = document.createElement("div");

                    // Create info-box
                    const $info = document.createElement("div");
                    fancybox.$info = $info;

                    // Add elements to DOM


                    fancybox.$leftCol = $leftCol;
                    fancybox.$rightCol = $rightCol;
                    "Carousel.ready Carousel.change": (fancybox, carousel, slideIndex) => {
                    // Update info-box
                    // ===

                    // Get index of the current gallery item
                    slideIndex = slideIndex || carousel.options.initialPage;

                    // Get link related to current item
                    const $trigger = fancybox.items[slideIndex].$trigger;

                    // Get data from `data-info` attribute
                    const data = $ || "";

                        type: "get",
                        url: `{{ url('/lightbox/${data}/info') }}`,
                        global: false,
                        success: function (response) {
                            fancybox.$info.innerHTML = response;
                        // , error: function (xhr, ajaxOptions, thrownError) {
                        //  console.log(xhr.status);
                        //  console.log(thrownError);
                        // }

I’ve successfully added an additional rightColumn (sidebar) to the fancybox (it’s not captured in the image below) as you can see from the setup. But now I want to add HTML content inside the area which fenced with a red marker on the image below. How can I add additional div with HTML elements in the fenced with a red marker area?



You can either create new element where you would place your content (similarly to creating additional elements in your sample) or you could just add additional content to your caption (there are samples in docs on the homepage)

Answered By – Janis

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published