javascript - 当鼠标悬停在该特定图像上时在图像上显示标题

标签 javascript php jquery wordpress

当我将鼠标悬停在该特定图像上时,我希望在图像上显示标题,现在当鼠标悬停在一张图像上时,它会显示在四张图像上。请帮我解决这个问题。

我使用的代码

<div class="post col-sm-3 col-xs-6 cat-<?php echo get_the_first_category_ID();?>"id="header-img">
    <a href="<?php the_permalink(); ?>" >
        <?php echo g7_image($image_w2, $image_h2, false); ?>
    </a>
    <header>
      <h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
    </header>
</div>

还有我使用的 Jquery

$(document).ready(function(){
$(".col-sm-6 h2, .col-sm-3 h2").hide();
});

$(document).ready(function(){
$(".post.col-sm-3.col-xs-6 img").mouseenter(function(){
$(".post.col-sm-3.col-xs-6 h2").show();
});
$(".post.col-sm-3.col-xs-6 img").mouseleave(function(){
$(".post.col-sm-3.col-xs-6 h2").hide();
});
});

这里我附上一张屏幕截图enter image description here

最佳答案

您可以使用 HTML 来获取此内容。

对于图像,请使用 ALT 文本:

<img src="images/example.jpg" alt="This is an example">

当用户将鼠标悬停在其上时,它将显示出来。

您可以对链接执行类似的操作,但使用 TITLE 选项。

<a href="example.com" title="Click to see an example">Example Link</a>

关于javascript - 当鼠标悬停在该特定图像上时在图像上显示标题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23852581/

相关文章:

javascript - 使没有内容的div水平滚动

javascript - 第一次点击 href 时出现 .collapse() 错误

php - 迁移后无法执行批量操作

javascript - 将 JSON 的 php 字符串(带引号)传递给 onclick 函数

php - 使用 PHP 确定文件类型。什么是魔法数据库?

javascript - 在事件的 Accordion 面板下选择一个类

javascript - 我想通过单击箭头导航使每个部分水平滚动?每个部分都有无限的垂直滚动

javascript - 我如何使用 "grant_type=client_credentials"发送 HTTP header

javascript - 将函数作为 props 传递给函数组件

javascript - 如何在 Javascript 或 jQuery 中检查 Textarea 是否为空?