Skip to content

Gallery: showing a caption

Chris Dowling edited this page Aug 2, 2014 · 8 revisions

While there's no mechanism built in Featherlight gallery to display captions, it's easy to add.

For example, the following code looks for an <img> tag within the current target (typically a <a> tag), retreives the value of the alt attribute and appends a <div> with that content.

$.featherlightGallery.prototype.afterSlide = function() {
  var caption = this.$elem.find('img').attr('alt');
  this.$instance.find('.caption').remove();
  $('<div class="caption">').text(caption).appendTo(this.$instance.find('.featherlight-content'));
};
Clone this wiki locally