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
JQUERY if not hover
提问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
回答by Sam
Could you add a class to #DIVB
on hover then check for it on mouseleave
for #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();
}
});