我正在尝试自定义 Galleria jQuery 插件,以允许使用 dataConfig 函数提供丰富的字幕,详见此处。图库的基本代码如下:
<div id="galleria">
<ul>
<li>
<img src="myimg.jpg">
<h2>Lorem ipsum title</h2>
<div class="desc">You can add <strong>strong</strong> tags or any other HTML as caption</div>
</li>
</ul>
</div>
<script>
$('#galleria').galleria({
dataConfig: function(img) {
return {
title: $(img).next('h2').html(), // tell Galleria to use the h2 as title
description: $(img).siblings(.desc).html() // tell Galleria to grab the content from the .desc div as caption
};
}
});
</script>
我遇到的问题是,如果我将 img 标签包装在锚点中,如下所示 -
<li>
<a href="full-size.jpg"><img src="myimg.jpg"></a>
<h2>Lorem ipsum title</h2>
<div class="desc">You can add <strong>strong</strong> tags or any other HTML as caption</div>
</li>
-- 允许在禁用 JS 时优雅降级 -- dataConfig 函数中的“title”和“description”引用不再起作用,因为我意识到 jQuery 正在寻找紧跟 img 标签的 H2 和“desc”类,并将其放置在锚点内似乎会在输入时破坏参考 - 即通过 (img).next 和 (img).siblings。因此,我的问题是如何更改这些标题和描述 jQuery 引用以使用位于锚标记内的图像。我意识到我可以将锚放在整个街区周围——即。img、h2 和“desc” div——我相信现在技术上允许在 HTML5 规范中,并且它将继续按照输入的方式工作,但我宁愿只包装 img。
我想这更像是一个基本的 jQuery 问题。非常感谢这里的任何帮助。