2010-10-29 79 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