jQuery 是一个快速、小巧且功能丰富的 JavaScript 库,它简化了 HTML 文档遍历、事件处理、动画和 Ajax 交互。鼠标悬停显示该行信息是一个常见的交互效果,通常用于表格或列表中,当用户将鼠标悬停在某一行时,显示该行的详细信息。
鼠标悬停显示信息的类型主要包括:
以下是一个使用 jQuery 实现鼠标悬停显示行信息的示例:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>jQuery Hover Example</title>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<style>
.hover-info {
display: none;
background-color: #f9f9f9;
padding: 5px;
border: 1px solid #ccc;
}
</style>
</head>
<body>
<table>
<tr>
<td>Item 1</td>
<td class="hover-info">Detailed info for Item 1</td>
</tr>
<tr>
<td>Item 2</td>
<td class="hover-info">Detailed info for Item 2</td>
</tr>
<tr>
<td>Item 3</td>
<td class="hover-info">Detailed info for Item 3</td>
</tr>
</table>
<script>
$(document).ready(function() {
$('table tr').hover(
function() {
$(this).find('.hover-info').show();
},
function() {
$(this).find('.hover-info').hide();
}
);
});
</script>
</body>
</html>
$(document).ready()
)。.hover-info
的位置,例如使用 position: absolute;
和 top: 0; left: 0;
。setTimeout
来实现延迟显示效果。通过以上方法,可以有效地实现鼠标悬停显示行信息的功能,并解决常见的相关问题。
领取专属 10元无门槛券
手把手带您无忧上云