2010-05-07 84 views
6

DIV A的Mouseenter将DIV B设置为show()。我要的是对DIV A的鼠标离开,如果他们不上空盘旋DIV B,隐藏DIV B.但是,在DIV A的鼠标离开,如果他们徘徊在DIV B保持显示DIV B.JQUERY if not hover

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

你可以显示标记吗? – Mark 2010-05-07 13:48:27

回答

4

它可能就像只使用hover一样简单。

http://jsbin.com/ojipu/2

...但是,这要看是什么标记的样子。

+0

它依靠Div B使用与Div A相同的空间,如果他们之间有距离,该怎么办? – fixmycode 2011-07-11 03:49:55

+0

我不确定你会如何离开Div A,如果它们没有重叠,仍然知道要显示Div B。 – Mark 2011-07-16 18:08:36

+0

我有同样的问题。检查此:http://stackoverflow.com/questions/6645551/how-to-interrupt-a-hovers-handlerout – fixmycode 2011-07-19 20:59:33

5

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

我实际上使用了你的两个解决方案。谢谢你们俩! – s15199d 2010-05-07 15:18:24