JQUERY 如果不悬停

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2788950/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 14:16:36  来源:igfitidea点击:

JQUERY if not hover

jquery

提问by s15199d

Mouseenter of DIV A sets DIV B to show(). What I want is on mouseleave of DIV A if they are nothovering over DIV B, hide DIV B. But, on mouseleave of DIV A if they are hovering over DIV B keep showing DIV B.

DIV A 的 Mouseenter 将 DIV B 设置为 show()。我想要的是在 DIV A 的 mouseleave 上,如果他们没有悬停在 DIV B 上,隐藏 DIV B。但是,如果他们悬停在 DIV B 上,则在 DIV A 的 mouseleave 上继续显示 DIV B。

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

采纳答案by Mark

It could be as simple as just using hover.

它可以像使用hover一样简单。

http://jsbin.com/ojipu/2

http://jsbin.com/ojipu/2

...but that depends on what the markup looks like.

...但这取决于标记的外观。

回答by Sam

Could you add a class to #DIVBon hover then check for it on mouseleavefor #DIVA?

你可以添加一个类#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();
    }
});