Mousemove事件会触发,但不应该触发

时间:2014-05-28 17:53:46

标签: jquery javascript-events mouseleave

我对.mouseleave()有疑问。 我想在用户用鼠标离开文档时显示弹出窗口,但mouseleave事件也会在输入文档时继续触发。

仅在Chrome中发生,在Mozzila中一切正常。

所以这就是代码:

$(document).mouseleave(function (e) {
    alert('The mouse has left the building!');
});

还有一件事:当我滚动时,事件也会触发。我能理解那一个,因为基本上我要离开文件了,但我可以阻止它吗?

1 个答案:

答案 0 :(得分:1)

以下是一种使用jQuery.hover()demo

的方法
$(document).hover(function () {
  $('body').css({'background-color': 'red'});
}, function () {
  $('body').css({'background-color': 'green'});
});