最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to add description text in FeatherLight Image Gallery? - Stack Overflow

programmeradmin0浏览0评论

Trying to figure out how to add a text description to featherlight.js lightbox image gallery. Does anybody know or have any experience?

Here's an example of how the html is laid out:

<div class="mix digital" data-myorder="12" style="display: inline-block;">
        <a class="gallery2" href="gallery_images/design/woodcut.jpg">
        <div class="thumbnail" style="background-image:url(gallery_images/design/woodcut_th.jpg);"></div></a>
    </div>

<div class="mix digital" data-myorder="11" style="display: inline-block;">
        <a class="gallery2" href="gallery_images/design/script.jpg">
        <div class="thumbnail" style="background-image:url(gallery_images/design/script_th.jpg);"></div></a>
    </div>

...plus many more images

I would just like to be able to add a little bit of text as a description of the images in the light box when they open up and I can't find this in the documentation.

If not, does anybody know of a good/light lightbox that could achieve this?

Trying to figure out how to add a text description to featherlight.js lightbox image gallery. Does anybody know or have any experience?

Here's an example of how the html is laid out:

<div class="mix digital" data-myorder="12" style="display: inline-block;">
        <a class="gallery2" href="gallery_images/design/woodcut.jpg">
        <div class="thumbnail" style="background-image:url(gallery_images/design/woodcut_th.jpg);"></div></a>
    </div>

<div class="mix digital" data-myorder="11" style="display: inline-block;">
        <a class="gallery2" href="gallery_images/design/script.jpg">
        <div class="thumbnail" style="background-image:url(gallery_images/design/script_th.jpg);"></div></a>
    </div>

...plus many more images

I would just like to be able to add a little bit of text as a description of the images in the light box when they open up and I can't find this in the documentation.

If not, does anybody know of a good/light lightbox that could achieve this?

Share Improve this question edited Sep 21, 2015 at 21:44 Simon Arnold 16.2k8 gold badges68 silver badges88 bronze badges asked Jan 19, 2015 at 4:35 nolaw09nolaw09 511 silver badge2 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 9

featherlight aims to be light and doesn't have a builtin option for this, but it's easy to do with the afterContent callback.

For example, imagine that your text is in the 'alt' attribute of the a tag, you could specify:

afterContent: function() {
    // Add a div for the legend if needed:
    this.$legend = this.$legend || $('<div class="legend"/>').insertAfter(this.$content);
    // Set the content:
    this.$legend.text(this.$currentTarget.attr('alt'));
}

Here's a working example.

发布评论

评论列表(0)

  1. 暂无评论