jQuery鼠标事件处理

时间:2011-04-28 07:12:36

标签: javascript jquery html mouseevent

我有以下代码:

HTML:

<div class="one">Content</div>
<div class="two">Content</div>

我希望在div事件从第一个mosueleave发生时隐藏我的第二个div,并且鼠标也不会超过第二个div

算法:

if ((mouseleave from div.one) && (mouse not on div.two))
     hide (div.two);

如何使用jquery实现此代码段?请帮我。

2 个答案:

答案 0 :(得分:2)

您可以在跟踪鼠标悬停状态的.two div上设置一个标志。然后,当鼠标离开.one时,您检查此状态,如果它存在,则隐藏div。像这样:

$(".two").live("mouseenter", function(){
    $(this).data("hover", true);
}).live("mouseleave", function(){
    $(this).removeData("hover");
});

$(".one").live("mouseleave", function(){
  if( !$(".two").data("hover") ) $(".two").hide();
});

答案 1 :(得分:1)

div括在另一个中,比如div class='zero'。所以你会在你的$(document).ready()喜欢

$('.zero').live('hover', function() {
  $('.two').show();
});

$('.zero').live('blur', function() {
  $('.two').hide();
});

注意:默认情况下,style="display: none"必须div class='two'

相关问题