2

在 prettyPhoto 中,我怎样才能让照片描述来自"title"(添加到<a>周围的标签<img>)以外的东西?将鼠标悬停在图像上时,它会在我的网站上显示丑陋的 html,我只想在它打开时由 prettyPhoto 看到和显示(因此它包含 html),而不是作为工具提示。

我的一个想法是插入一个事件,但唯一相关的是changepicturecallback,我不知道如何从中访问当前的照片元素。

也许它是 jQuery 本身的东西,但我有点不知道在哪里可以找到它。

任何想法都会有所帮助。

谢谢,伊戈尔

4

8 回答 8

10

希望现在回答你的问题还不算晚,但我最近不得不修改漂亮的照片代码来做你所要求的。

有一行从锚的“标题”属性设置描述。您可以更改它以从任何您想要的地方获取描述。我决定在存储描述的锚点下创建一个 <p> 标记。

要更改描述的来源,您必须修改漂亮的照片源。找到如下所示的行:

pp_descriptions = (isSet) ? jQuery.map(matchedObjects, function(n, i){ if($(n).attr('rel').indexOf(theRel) != -1) return ($(n).attr('title')) ? $(n).attr('title') : ""; }) : $.makeArray($(this).attr('title'));

它应该在第 152 行,至少从 3.1.3 版开始。只需使用查找和替换工具来搜索“pp_descriptions”。

将其更改为:

pp_descriptions = (isSet) ? jQuery.map(matchedObjects, function(n, i){ if($(n).attr('rel').indexOf(theRel) != -1) return ($(n).find('p').text()) ? $(n).find('p').text() : ""; }) : $.makeArray($(this).find('p').text());

将“(this).attr('title')”更改为“.find('p').text()”将在锚中定位一个<p>标签,而不是使用“title”属性。您可能想用 CSS 隐藏 <p> 标记,这样它就不会显示在您的网站上。

现在 html 标记应如下所示:

<a href="path/to/your/big-image.jpg" rel="prettyPhoto">
    <p>This is the Description</p>
    <img src="path/to/your/small-image.jpg" alt="caption text" />
</a>
于 2012-03-02T14:42:36.330 回答
1

我有类似的问题。但在我的情况下,只显示了第一个单词,因为 HTML 标记中缺少双引号,在这种情况下,请确保 HTML 中有title=标记并被引用

<a title="Your Title Quoted" href="path/to/your/big-image.jpg" rel="prettyPhoto">
    <img src="path/to/your/small-image.jpg" alt="caption text" />
</a>

希望这也会有所帮助。

于 2012-12-13T14:28:48.097 回答
1

我也遇到了这个问题,发现这篇文章对我很有帮助:

在 PrettyPhoto Captions 中使用 HTML 格式

我知道这个问题已经得到解答,但我相信这种方法可以在格式方面提供更多自由。

引用文章:

从您的站点打开 jquery.prettyPhoto.js 文件并找到包含以下代码的行:

pp_descriptions=isSet?jQuery.map(o,function(t,n){if(e(t).attr(settings.hook).indexOf(theRel)!=-1)return e(t).attr("title ")?e(t).attr("title"):""}):e.makeArray(e(this).attr("title"));

然后用 'alt' 属性替换它:

pp_descriptions=isSet?jQuery.map(o,function(t,n){if(e(t).attr(settings.hook).indexOf(theRel)!=-1)return e(t).attr("alt ")?e(t).attr("alt"):""}):e.makeArray(e(this).attr("alt"));

这很好用,你可以使用“h2”标签和“p”标签来格式化你的标题。 但这不允许W3 Validator 验证页面。

因此,我没有使用“alt”属性,而是简单地将其替换为“aria-label”属性,瞧!它按预期工作并允许验证页面。

示例代码:

<a href="path/to/your/big-image.jpg" rel="prettyPhoto" title="This is the native tooltip" aria-label="<h2> This is a caption.</h2> This caption has formatting and does not interfere with the native tooltips.">
    <img src="path/to/your/small-image.jpg" alt="alt-text" />
</a>
于 2015-09-03T13:30:03.763 回答
0

这很好,但是如果我希望在标签中包含中断标签
或重音标题,则此信息似乎不起作用,否则它会破坏功能。我不敢相信漂亮的照片会让禁用工具提示变得如此困难.....

谁真的希望他们的描述用所有这些代码突出显示?:P

于 2012-04-16T20:10:57.300 回答
0

谢谢凯尔!!!!这真的把我逼疯了,最后你给我指路了。:) 如果您不想显示任何工具提示,我想添加,只需在 img 标题中添加一个空格,即:title="" 否则它会忽略它并返回锚标题。再次感谢!

于 2012-10-10T17:03:54.180 回答
0

当您使用tipsy.js时,只需要在jquery.prettyPhoto.js中将“title”属性交换为“original-title” 。

像这样:

pp_descriptions=(isSet)?jQuery.map(matchedObjects,function(n,i){if($(n).attr('rel').indexOf(theRel)!=-1)return($(n).attr('original-title'))?$(n).attr('original-title'):"";}):$.makeArray($(this).attr('original-title'))
于 2013-04-20T10:21:48.357 回答
0

基于米切尔所说的:

我使用 .html() 而不是 .text() 因为我使用了嵌套样式跨度:

<span class="popup_text_cont">
      <span class="popup_caption_cont">
        <span class="popup_detail">
          <span class="popup_caption">Client</span>
          <span class="popup_basic_info">Playhouse Square Foundation</span>
        </span>
        <span class="popup_detail">
          <span class="popup_caption">Project</span>
          <span class="popup_basic_info">Broadway Buzz eNewsletter</span>
        </span>
        <span class="popup_detail">
          <span class="popup_caption">Skills</span>
          <span class="popup_basic_info">HTML, CSS</span>
        </span>
      </span>
      <span class="popup_description">
        Designed and implemented a templated eNewsletter that was distributed to theatergoers and Playhouse Square sponsors.
      </span>
    </span>

用这样的东西替换(在未压缩版本中对我来说是第 155 行)。

if($(n).attr(settings.hook).indexOf(theRel) != -1) return ($(n).find('span.popup_text_cont').html()) ? $(n).find('span.popup_text_cont').html() : ""; }) : $.makeArray($(this).find('span.popup_text_cont').html());    
于 2013-07-30T02:33:33.627 回答
0

只需添加这个

font-size: 0px !important;

于 2015-08-31T21:14:06.030 回答