简体   繁体   English

如何在悬停时显示图片标题文字?

[英]How to show image title text on hover?

I'm building a basic Wordpress website. 我正在构建一个基本的Wordpress网站。 This is the demo page I need help with: 这是我需要帮助的演示页面:

http://irontemplates.com/wp-themes/ironband/photos/ http://irontemplates.com/wp-themes/ironband/photos/

When mouse is hovered over the image, I want it to show the title of the image before it says "View Image." 当鼠标悬停在图像上时,我希望它在显示“查看图像”之前显示图像的标题。

This is javascript or jQuery I'm assuming? 这是我假设的javascript或jQuery? Can anyone give me a sample code of how I would go about this? 任何人都可以给我一个示例代码,我将如何解决这个问题?

The View-Image is a new link to the real image, or the full sized image. View-Image是指向真实图像或全尺寸图像的新链接。 Which can have the title of the image Just like this: 哪个可以有图像的标题就像这样:

<a href="#" title="title to show">
  <img src="source/to/file.ng" alt="photo" />
</a>

This way, you will show the image title in the link.. 这样,您将在链接中显示图像标题。

var title= $("#imageid").attr("title");

Then on hover: 然后在悬停:

$("#imageid").on("hover",function(){
    alert(title);
});

Try this. 试试这个。

<a href="http://irontemplates.com/wp-themes/ironband/content/uploads/2013/08/photo_2112.jpg" rel="lightbox" class="lightbox hoverZoomLink">
    <img src="http://irontemplates.com/wp-themes/ironband/content/uploads/2013/08/photo_2112-300x230.jpg" width="352" height="347" alt="">
        <span class="hover-text"><span>VIEW IMAGE</span></span>
    </a>

This is found inside a list element that exists within an unsorted list that holds all of the images for that page. 这是在列表元素中找到的,该列表元素存在于未排序列表中,该列表包含该页面的所有图像。

You need to change what is between the innermost span tags. 您需要更改最里面的span标记之间的内容。 In this case, it says "VIEW IMAGE", change it to "Image 1" or whatever you want. 在这种情况下,它会显示“VIEW IMAGE”,将其更改为“Image 1”或您想要的任何内容。

You can use Javascript to dynamically name them for you, but that wasn't exactly your question! 您可以使用Javascript为您动态命名,但这不是您的问题!

You can do that with JS: 你可以用JS做到这一点:

var ls_input_section_header = document.createElement("img");   
ls_input_section_header.title="info to display on hover of info";
ls_input_section_header.className="ls_input_section_header_gs";
ls_input_section_header.setAttribute("src","style/img/info.gif");
ls_input_section.appendChild(ls_input_section_header);   

Or you can use CSS only 或者您只能使用CSS

.ls_input_section_header_gs
{   
 position: absolute;
    top: 15px;    
}
    .ls_input_section_header_gs a:hover:after {
  content: attr(title);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM