来自兄弟容器的FancyBox的头衔

时间:2014-08-13 18:26:25

标签: javascript jquery html fancybox

我遇到了一个非常简单/愚蠢的问题,而我缺乏jQuery知识并没有帮助。

原则上我有一个带有多张图片的厨房,并希望使用一个兄弟 - <div> - 块和一些HTML标记作为FancyBox的标题。这是我的问题的一个简单的小提琴:

HTML:

<div class="someClass">
  <a title="some title"
     class="fancybox"
     href="http://fancyapps.com/fancybox/demo/1_b.jpg">
    <img src="http://fancyapps.com/fancybox/demo/1_s.jpg"
         alt=""/>
  </a>
</div>

<div class="captionClass">
     this should be <br /> the <b>caption</b>
</div>

JavaScript的:

$(".fancybox").fancybox({

  'beforeLoad' : function() {
     this.title = $(this).siblings('.captionClass').html();
  }

 });

非常感谢任何帮助:)

1 个答案:

答案 0 :(得分:1)

您应该将功能更改为afterLoad

$(".fancybox").fancybox({
    afterLoad: function () {
        this.title = $(this.element).parent().siblings('.captionClass').html()
    },
    helpers: {
        overlay: {
            css: {
                'background': 'rgba(58, 42, 45, 0.95)'
            }
        }
    }
});

DEMO:http://jsfiddle.net/6gvjsd9u/