2010-10-29 53 views

回答

3

可以使用.hover()the fading functions做一些可重复使用的,就像这样:

$(".container").hover(function() { 
    $(this).find(".hover").fadeIn(); 
}, function() { 
    $(this).find(".hover").fadeOut(); 
}); 

例如,这里的演示标记,虽然<div>元素可以包含任何内容:

<div class="container"> 
    <div class="hover"> 
     Content Here 
    </div> 
    <a href="#">Link</a> 
</div> 

然后通过CSS,你只需将其放在<div>的内部,并给它相同的大小,如下所示:

.container, .hover { width: 100px; height: 300px; background: white; } 
.hover { position: absolute; display: none; } 

You can give it a try here

+0

+1的CSS部分,看到你的演示后,我意识到我没有做,他是什么寻找:) – Sarfraz 2010-10-29 11:10:39

0

对于您需要使用特别的JQuery事件.hover()。一旦你掌握了它,你会发现做这种工作跨浏览器的任务是微不足道的。

3

HTML:

<div id="container"> 
    <a href="#" id="link">Link</a> 
    <div id="divtofadein">some content here</div> 
</div> 

JS:

$(function(){ 
$("#divtofadein").mouseout(function(){ 
    $(this).fadeOut(); 
}) 
    .hide(); 

$("#link").click(function(){ 
    $("#divtofadein").fadeIn(); 
}); 
}); 

CSS:

#container { 
position: relative; 
width: 100px; 
height: 200px; 
} 

#link { 
position: absolute; 
top: 0px; 
left: 0px; 
} 

#divtofadein { 
position: absolute; 
top: 0px; 
left: 0px; 
width: 100px; 
height: 200px; 
background: #FFF; 
} 
+1

恭喜你的第一个答案 – 2010-10-29 11:10:34