2012-03-14 69 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

相关问题