JQUERY如果没有悬停

s15*_*99d 10 jquery

DIV A的Mouseenter将DIV B设置为show().我想要的是DIV A的鼠标离开,如果他们没有在DIV B上空盘旋,则隐藏DIV B.但是,如果他们在DIV B上空盘旋,则在DIV A的鼠标上继续显示DIV B.

$('#DIVA').mouseenter(function() {
        $('#DIVB').show();  
    }).mouseleave(function() {      
        //if DIVB not hovering
            $('#DIVB').hide();
        //end if
    });
Run Code Online (Sandbox Code Playgroud)

Sam*_*Sam 11

你可以添加一个类#DIVB上悬停,然后检查它mouseleave#DIVA

$('#DIVB').hover(function(){
    $(this).addClass('active');
}, function(){
    $(this).removeClass('active');
})

$('#DIVA').mouseenter(function() {
    $('#DIVB').show();  
}).mouseleave(function() {      
    if(!$('#DIVB').hasClass('active')){
        $('#DIVB').hide();
    }
});
Run Code Online (Sandbox Code Playgroud)


Mar*_*ark 6

它可以像使用悬停一样简单.

http://jsbin.com/ojipu/2

...但这取决于标记的样子.