使用jQuery悬停在div上时如何显示覆盖div? [英] How to show an overlay div when hover on a div with jQuery?
本文介绍了使用jQuery悬停在div上时如何显示覆盖div?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在悬停的 div 上显示一个覆盖 div,类似于 IBM 网站上的这种效果:http://www.ibm.com/us/en/
I want to show an overlay div sitting on top of the hovered div similar to this effect on IBM website: http://www.ibm.com/us/en/
请查看页脚附近的 3 个方框.将鼠标悬停在让我们建设一个更智能的星球"框上查看效果.
Please look at the 3 boxes near the footer. Hover on the box "Let's build a smarter planet" to view the effect.
推荐答案
我创建了一个 工作示例一个>.基本上,您需要创建 3 个具有可见和不可见容器的 div,添加 hover 事件处理程序并在该处理程序中切换 tooltip 的 可见性.
I've created a working example. Basically you need to create 3 divs with a visible and the invisible containers, add hover event handler and toggle the tooltip's visibility in that handler.
HTML:
<div class="parents">
<div class="box type-1">box 1</div>
<div class="tooltip type-1">tooltip 1</div>
</div>
<div class="parents">
<div class="box type-2">box 2</div>
<div class="tooltip type-2">tooltip 2</div>
</div>
<div class="parents">
<div class="box type-3">box 3</div>
<div class="tooltip type-3">tooltip 3</div>
</div>
CSS:
.parents
{
float: left;
margin: 5px;
}
.box,
.tooltip
{
width: 80px;
height: 30px;
line-height: 30px;
background-color: #666;
color: #fff;
border: 1px solid #222;
text-align: center;
}
.tooltip
{
display: none;
position: absolute;
top: 50px;
}
jQuery 代码:
$(document).ready
(
function ()
{
// add hover event handler
$('.box').hover
(
function ()
{
// find the triggering box parent, and it's tooltip child
$(this).parent().children('.tooltip').animate
(
{
opacity: "toggle", // toggle opacity
}
);
}
);
}
);
这篇关于使用jQuery悬停在div上时如何显示覆盖div?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文