【问题标题】:fancybox and wordpress: image titlesfancybox 和 wordpress:图片标题
【发布时间】:2013-03-10 05:03:11
【问题描述】:

我的fancybox 在没有插件的情况下可以很好地与wordpress 配合使用,但在图片标题方面却遇到了困难。

fancybox 正在寻找标题的锚点,但 wordpress 将标题放在 img 中。

我查看了所有解决方法并尝试了所有 stackoverflow 解决方案,但似乎没有任何效果。

我认为有两种选择: 1. 告诉 fancybox 使用 img 标题(或 alt)而不是锚标题 2. 运行函数提取附件标题并插入到锚中

周围有很多解决方案,但我显然做错了什么。

有什么建议吗?

【问题讨论】:

  • 第一个告诉fancybox使用图像alt标签:)

标签: jquery wordpress fancybox fancybox-2


【解决方案1】:

您可以使用beforeShow fancybox 的回调来获取<img> 标记中alt 或title 属性的值,例如:

$(".fancybox").fancybox({
    beforeShow: function () {
        // option 1
        // get the title from "alt" attribute
        this.title = $(this.element).find("img").attr("alt");
        // option 2
        // get the title from "title" attribute in img tag
        // this.title = $(this.element).find("img").attr("title");
    }
});

见JSFIDDLE

【讨论】:

  • 感谢 JFK,我在另一个论坛上看到了这个答案,但无法让它发挥作用。问题似乎是如果我在 beforeshow 回调中使用 helper。添加:helpers: { title : { type : 'inside' } },标题不再显示
  • @fisicx :它确实有效,检查 updated JSFIDDLE。您很可能忘记用逗号分隔选项 ,
  • 是的,这就是问题所在。谢谢
  • @fisicx :那么您可以接受答案以将其关闭meta.stackexchange.com/a/5235 谢谢。
猜你喜欢
  • 1970-01-01
  • 2019-12-11
  • 1970-01-01
  • 2014-09-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多