0

我一直在努力解决似乎应该是一个简单的问题:

我继承了一个站点,该站点使用了滑块和 jquery backstretch 的组合。客户要求其中一张幻灯片有标题,位于图像的可见底部。

所以我想转这个:

<div id="backstretch" style="…">
<img style="…">
</div>

进入这个:

<div id="backstretch" style="…">
<img style="…">
<div class="gallery-caption">Caption</div>
</div>

并销毁 div 的每个实例,就像处理图像一样。

但是,我似乎无法让 javascript 呈现标题 div,并使其与导航保持同步。为了清水起见,我把所有的尝试都去掉了,回到我一开始的 JS 代码。

这是一个例子:http ://tylonius.net/backstretch/lifestyle-gallery.html

有人能帮忙吗?

4

1 回答 1

0

其他答案不相关,我没有注意到它是 FancyBox。

一个类似的问题张贴在这里这里这里。正如@JFK 在第一个链接中所说,您可以使用图像属性的 data-, 前缀来保存标题信息。并使用 jquery 脚本访问它。

<!doctype html>
<html>
<head>
 . . . 
    <title>your demo</title>
</head>

<body>
    <div id="gallery" class="residences">
        <div class="bigImages">
            <ul>
                <li>
                    <div class="gallery-image">
                            <img class="caption" src="images/lifestyle-gallery/img2.jpg" title="Caption 1" data-caption="Caption will go here">
                     </div> <!-- /gallery-image -->
                </li>

脚本将是:

$(document).ready(function() {
    $(".fancybox").fancybox({
        helpers : {
        title: { type: 'inside'}
    },
    // use the following if you want to do the caption before the image
    // beforeShow : function(){ 
    afterLoad: function(){
        this.title = this.title + ' ' + $(this.element).data("caption");
        //you can also do the following to use the alt instead of the caption
        //this.title = this.title + ' ' + $(this.element).find('img').attr('alt');
    }

    }); // fancybox
}); // ready
于 2014-10-07T02:02:24.893 回答