我有兩個div:紅色的藍色。 我想當用戶將這個fadeOut懸停在紅色並且當懸停在背景(當他突然出現藍色時)紅色淡入。 (更令人驚訝的是,當我徘徊在背景中但當我將鼠標移到背景上時,紅色褪色了嗎?我不明白)懸停和切換jQuery
這裏的例子生活:http://jsfiddle.net/DpD8S/
HTML:
<div id="background">
<div id="red"></div>
<div id="blue"></div>
</div>
CSS:
#red{
position:absolute;
top: 20px;
left: 20px;
width: 60px;
height: 30px;
background-color:red;
cursor: pointer;
z-index: 1;
}
#blue{
position:absolute;
top: 20px;
left: 20px;
width: 60px;
height: 30px;
background-color:blue;
cursor: pointer;
}
#background{
position: relative;
margin: 0 auto;
width:300px;
height: 300px;
border: 1px solid;
border-color:#CCC;
text-align: center;
cursor: pointer; }
JQUERY:
$(function(){
$("#red").hover(function() {
$("#red").fadeOut();
});
$("#background").hover(function() {
$("#red").fadeIn("normal");
});
})
如果我理解正確的話,的jsfiddle就像你所描述的 – dualed
「我想,當用戶將鼠標懸停在紅色,這種淡出當懸停在背景中,紅色淡入「現在,當我將鼠標懸停在背景上時,紅色不會淡入。我不明白爲什麼? – Nrc
我想我明白了...... – dualed