如何将“标题”属性发送到FancyBox库图像
How to send a Title attribute to a FancyBox gallery image?
我正在尝试将标题属性加载到FancyBox安装的弹出库图像上。因为图库是从页面上的标签动态加载的,所以我不能直接将标题放在标签上。此外,当我将title属性添加到标记时,它只用于可见的标题。
我需要的是一种方法,将图库标签上使用的标题添加为实际展开图像上的标题属性。我需要这个的唯一原因是,当使用Pinterest按钮时,Pinterest使用title属性来填充描述。
我在页面上的代码是:
<div id="gal1180">
<a href=“/path_to_image.jpg" class="fancybox" rel="gal1180" caption=“Test caption“>1</a>
<a href=“/path_to_image_2.jpg" class="fancybox" rel="gal1180" caption=“Test caption 2“>2</a>
<a href=“/path_to_image_3.jpg" class="fancybox" rel="gal1180" caption=“Test caption 3“>3</a>
</div>
我用来启动FancyBox的代码是:
$('.fancybox').fancybox({
helpers: {
overlay: {
locked: false
}
},
beforeLoad: function() {
this.title = $(this.element).attr('caption');
},
afterShow: function() {
touchSupport();
}
});
如有任何帮助,我们将不胜感激。
试试这个
beforeLoad: function() {
$(this).attr("title", $(this).attr('caption'));
}
或者如果在这种情况下元素在这个元素内
beforeLoad: function() {
$(this.element).attr("title", $(this.element).attr('caption'));
}
但是,如果dom没有在"beforeLoad"中加载,请在显示后尝试此操作
afterShow: function() {
touchSupport();
$(this.element).attr("title", $(this.element).attr('caption'));
// or $(this).attr("title", $(this).attr('caption'));
}
编辑:
试试这个
$("#gal1180").fancybox({
...
onComplete: function() {
$(".fancybox").each(function() {
$(this).attr("title", $(this).attr("caption"));
});
}
});
感谢Flyde提供的一些想法。这最终奏效了。
$('.fancybox').fancybox({
afterShow: function() {
$(".fancybox-image").attr("title", $(this.element).attr('caption'));
}
});
希望这对将来的其他人有所帮助。
这对我有效。
fancybox图片:
<a id="mbimageref" href="" data-fancybox data-caption="" data-close-btn-
text="X">path to your image.....</a>
动态加载字幕的脚本
<script>
var plaintext = "whatever your want the caption to be";
$("#mbimageref").attr('data-caption',plaintext);
</script>
相关文章:
- 当页面包含指向一个图像的多个链接时,fancyBox会复制缩略图辅助图像
- Fancybox画廊重复图像
- 运行fancybox thumb时隐藏其他图像
- fancybox 2图像刷新
- Fancybox图像点击可以独立工作,但不能与我的其他代码一起工作
- 阻止Fancybox显示图像
- Anythingsslider+Fancybox复制图像
- 在fancybox中显示动态图像
- 结合freewall.js和fancybox.js在Rails项目中获得可点击的放大图像
- Fancybox在第二次单击时响应,并且不会切换到下一个图像
- Fancybox - 将图像和 iframe 组合在一个图库中
- Fancybox 加载,但不包含任何图像,即使我很确定图像在正确的位置
- 如何在Wordpress Fancybox图像上将文本超链接到外部网站
- 如何添加指向 Fancybox 的链接以下载图像的高分辨率版本
- JQuery & Fancybox 单击图像以打开新页面/链接(更新现有代码)
- 如何将“标题”属性发送到FancyBox库图像
- Fancybox:如何滚动HTML片段,而不是具有相同效果的图像
- fancybox指令未对图像进行分组
- 使用jQuery预加载fancybox图像iframe
- Fancybox-图像不调整大小