jQuery绑定到多个元素

jQuery绑定到多个元素,jquery,bind,Jquery,Bind,我有: <div class='someclass'>Text</div> <div class='otherclass'>Other Text</div> <style> .someclass{ width:400px; height:200px; } .otherclass{ width:400px; height:200px;

我有:

<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时闪烁


我想,我可以使用超时,但有更好的方法吗?谢谢

我猜您正在将其用于导航子菜单或类似功能


我建议将.otherclass嵌套在.someclass中。

我猜您正在将其用于导航子菜单或类似功能


我建议将.otherclass嵌套在.someclass中。

能否将两个div包装在另一个元素中,并将悬停函数放在该外部元素上。这应该涵盖介于两者之间的时间。

能否将两个div包装在另一个元素中,并将悬停函数放在该外部元素上。这应该涵盖你处于两者之间的时间。

将“otherclass”放入“someclass”,并设置为someclass最小高度:200px

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

一些文本
文本

将“otherclass”放入“someclass”,并设置为someclass最小高度:200px

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

一些文本
文本

是的,关于子菜单,但是第二个div有位置:绝对,所以第一个div的尺寸不会改变,当第二个div淡入时…是的,关于子菜单,但是第二个div有位置:绝对,所以第一个div的尺寸不会改变,当第二个div淡入时…解决。我刚刚不得不用mouseleave而不是mouseout。它适用于位置:绝对(如果嵌套)。已解决。我刚刚不得不用mouseleave而不是mouseout。它适用于位置:绝对(如果嵌套)。