question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Possible to have both title and caption?

See original GitHub issue

Trying to use your script in my current project. I make a gallery and there is need to have both titles and captions for the popup images. For example, my html code:

<div class="popup-demo">
    <a href="images/demo-01.png" title="caption text">
        <img src="images/demo-01-tb.png" alt="title text" width="200" height="100" />
    </a>
    <a href="images/demo-02.png" title="caption text">
        <img src="images/demo-02-tb.png" alt="title text" width="200" height="100" />
    </a>
    ...
</div>

The popup window should consist of the following elements: Title Image Caption

The popup template code is something like this:

image: {
    markup: '<div class="mfp-figure">'+
            '<div class="mfp-close"></div>'+
            '<div class="mfp-another-title"></div>'+
            '<div class="mfp-img"></div>'+
            '<div class="mfp-bottom-bar">'+
                '<div class="mfp-title"></div>'+
            '</div>'+
        '</div>'
    }

It’s easy to retrieve text from link title attribute, but I don’t see how to retrieve text from image alt attribute so that I could use both of them simultaneously in markup template.

Is this possible? How could I do that?

Thanks, Alex

Issue Analytics

  • State:closed
  • Created 10 years ago
  • Comments:7 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
slaFFikcommented, May 24, 2018

For future searchers, I did that like this:

$('.the-menu-item-img').magnificPopup({
    type: 'image',
    image: {
        titleSrc: false,
        markup: '<div class="mfp-figure">'+
                  '<div class="mfp-close"></div>'+
                  '<div class="mfp-top-bar"></div>'+
                  '<div class="mfp-img"></div>'+
                  '<div class="mfp-bottom-bar">'+
                    '<div class="mfp-title"></div>'+
                    '<div class="mfp-counter"></div>'+
                  '</div>'+
                '</div>', // Popup HTML markup. `.mfp-img` div will be replaced with img tag, `.mfp-close` by close button
    },
    callbacks: {
        // this - is Magnific Popup object.
        change: function() {
            $(this.content)
                .find('.mfp-top-bar')
                .html(
                    '<h5>' +
                        $(this.currItem.el).attr('title') +
                    '</h5>'
                );
        }
    },
    gallery: {
        enabled: true
    }
});

Note the .mfp-top-bar in markup and logic in change event.

1reaction
shurcommented, Sep 5, 2013

Before asking the question I had studied the documentation and examples on codepen. But I didn’t find any example how to display title and caption as separate text blocks, and to have the title above the image, and the caption below the image.

I know about titleSrc, but it retrieves the text only in one text block <div class="mfp-title"></div>. I was trying to apply this code but it doesn’t solve the task.

titleSrc: function(item) {
    return '<h3>' + item.el.find('img').attr('alt') + '</h3>' + item.el.attr('title');
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

Display both short and long title in a caption with subcaption ...
The caption package has some \AtBeginDocument hook that detect if the \caption command has changed from its original definition.
Read more >
How to keep a figure on the same page as its caption in ...
Make sure the title or caption is not in a text box. That is, it has to be ordinary text. Select both the...
Read more >
GGPlot Title, Subtitle and Caption : The Ultimate Guide
This article describes how to add and change a main title, a subtitle and a caption to a graph generated using the ggplot2...
Read more >
Add titles, captions, and more to photos using Photos on Mac
You can assign titles and captions to photos, add or change the location of photos, and change the date and time information for...
Read more >
Word>how to have two formats in the Caption style: Label ...
No, you have one Style for the Caption and, after creating the caption, with its text, you apply a Character Style to the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found