Lon*_*yen 4 jquery overlay hover
我想在IBM网站上显示一个覆盖div的顶部div,类似于这种效果:http://www.ibm.com/us/en/
请查看页脚附近的3个框.将鼠标悬停在"让我们构建一个更智能的星球"框中以查看效果.
我已经创建了一个工作示例.基本上你需要创建3个带有可见和不可见容器的div,添加悬停事件处理程序并切换工具提示在该处理程序中的可见性.
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>
Run Code Online (Sandbox Code Playgroud)
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;
}
Run Code Online (Sandbox Code Playgroud)
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
}
);
}
);
}
);
Run Code Online (Sandbox Code Playgroud)