2012-03-14 64 views
0

我有:jQuery的綁定到多個元素

<div class='someclass'>Text</div> 
<div class='otherclass'>Other Text</div> 
<style> 
    .someclass{ 
     width:400px; 
     height:200px; 
    } 
    .otherclass{ 
     width:400px; 
     height:200px; 
     display:none; 
    } 
</style> 

$('.someclass').mouseover(function(){ 
    $('.otherclass').fadeIn(); 
}); 
$('.someclass).mouseout(function(){ 
    $('.otherclass').fadeOut(); 
}); 

,但我不想第二個div淡出如果光標越過這第二個div。

我可以使用

$('.someclass,.otherclass').mouseover(function(){ 
    $('.otherclass').fadeIn(); 
}); 
$('.someclass,.otherclass').mouseout(function(){ 
    $('.otherclass').fadeOut(); 
}); 

但它閃爍通過跨越從一個DIV到另一個。

我想,我可以使用超時,但有沒有更好的方法?謝謝!

+0

已解決。 我剛剛使用mouseleave而不是mouseout。它適用於位置:如果嵌套,則爲絕對。 – Sobakinet 2012-03-14 19:23:32

回答

1

我猜你正在使用這個用於導航子菜單或類似的東西。

我會建議在.someclass中嵌套.otherclass。

+0

是的,這是關於子菜單,但第二個div有位置:絕對,所以第一個div的尺寸不會改變,當第二個div淡入... – Sobakinet 2012-03-14 19:07:06

1

您可以將兩個DIV包裝到另一個元素中,並將懸停功能放在該外部元素上。這應該涵蓋你在兩者之間的時間。

+0

我已經回答上面,thx – Sobakinet 2012-03-14 19:11:05

1

把'otherclass'放到'someclass'中,並設置在某個類中min-height:200px;

<div class="someclass"> 
<div>Some text</div> 
<div class="otherclass">text</div> 
</div> 
+0

我已經回答上面,thx – Sobakinet 2012-03-14 19:10:44

相關問題