漂亮照片,“标题”;和工具提示

发布于 2024-12-25 22:18:20 字数 360 浏览 4 评论 0原文

在 PrettyPhoto 中,如何让照片描述来自 "title" 以外的内容(添加到 < 周围的 标签中) /代码>)?当将鼠标悬停在图像上时,它会在我的网站上显示丑陋的 html,我只想在打开时由 PrettyPhoto 看到和显示(因此它包含 html),但不作为工具提示。

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

也许这是 jQuery 本身的东西,但我有点迷失在哪里可以找到它。

任何想法都会有所帮助。

谢谢, 伊戈尔

In prettyPhoto, how can I have the photo description come from something other than "title" (added to <a> tag surrounding the <img>)? When hovering over the image, it displays ugly html on my website that I only want to be seen and displayed by prettyPhoto when it opens (hence it contains html), but not as a tooltip.

One thought I had was to plug into an event but the only one relevant is changepicturecallback, and I can't figure out how to access the current photo element from that.

Maybe it's something in jQuery itself but I'm a little lost as to where to find it.

Any idea would help.

Thanks,
Igor

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(8

蓝眸 2025-01-01 22:18:20

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

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

存储描述的锚点下的标签。

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

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()”将找到

;锚点中的标签而不是使用“标题”属性。您可能想隐藏

使用 CSS 标记,使其不会显示在您的网站上。

现在 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>

Hopefully this isnt to late to answer your question, but i had to modify the pretty photo code recently to do just what you are asking.

there is a line that sets the description from the 'title' attribute of the anchor. You can change it to get the description from wherever you want. I decided to create a <p> tag under the anchor that stores the description.

To change where the description comes from, you have to modify pretty photos source. find the line that looks like this:

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'));

it should be on line 152, atleast as of version 3.1.3. Just use a find and replace tool to search for "pp_descriptions."

change it to this:

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());

changing the "(this).attr('title')" to ".find('p').text()" will locate a <p> tag in the anchor instead of using the "title" attribute. You will probably want to hide the <p> tag with CSS so it doesnt display on your site.

now the html markup should look like this:

<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>
回忆追雨的时光 2025-01-01 22:18:20

我有类似的问题。但在我的例子中,只显示了第一个单词,因为 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>

希望这也会有所帮助。

I had similar problem. But in my case only first word was displayed, as there was missing a double quotation marks in HTML markup, in this case, make sure that there is title= markup in your HTML and is quoted:

<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>

Hope this will help too.

み青杉依旧 2025-01-01 22:18:20

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

在 PrettyPhoto 标题中使用 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("标题")?e(t).attr("标题"):""}):e.makeArray(e(this).attr("标题"));

然后将其替换为 '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 验证器验证页面。

因此,我没有使用“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>

I was also experiencing this problem and found this article which really helped me:

Using HTML Formatting in PrettyPhoto Captions

I know this question has already been answered, but i believe this method allows for more freedom in terms of formatting.

Quote from article:

Open the jquery.prettyPhoto.js file from your site and locate the line
that contains the following code:

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"));

And then replace it with the 'alt' attribute:

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"));

This works great, you can use "h2" tags and "p" tags to format your caption. BUT this does not allow the page to be validated by the W3 Validator.

So instead of using the 'alt' attribute, i simply replaced it with the'aria-label' attribute and voila! It works as expected and allows the page to be validated.

Example Code:

<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>
别低头,皇冠会掉 2025-01-01 22:18:20

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

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

This is great however if I wish to include break tags
or accent titles with the tag this information doesn't seem to work or else it breaks the functionality. I can't believe pretty photo would make it this difficult for tooltips to be disabled.....

Who really wants their description to be highlighted with all that code? :P

丶情人眼里出诗心の 2025-01-01 22:18:20

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

Thank-you Kyle!!!!! That really drove me crazy and finally you showed me the way. :) I'd like to add if you don't want any tooltip to show up, just add a blank space to the img title, ie: title=" " otherwise it ignores it and goes back to the anchor title. Thanks again!

这样的小城市 2025-01-01 22:18:20

当您使用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'))

when you use tipsy.js, can neeed to only exchanage "title" attribute to "original-title" in jquery.prettyPhoto.js.

like this:

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'))
谎言月老 2025-01-01 22:18:20

根据 Mitchell 所说:

我使用 .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());    

Building on what Mitchell said:

I used .html() instead of .text() because I used nested styled spans :

<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>

Replace (what was line 155 for me in the uncompressed version) with something like this.

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());    
网名女生简单气质 2025-01-01 22:18:20

只需添加此

font-size: 0px !important;

Just add this

font-size: 0px !important;

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文