【发布时间】:2015-09-03 22:20:00
【问题描述】:
我正在使用此代码来检测鼠标离开窗口,并且效果很好。
jQuery(document).mouseleave(function(){console.log('out')})
jQuery(document).mouseenter(function(){console.log('in')});
但在 chrome 中,即使在触摸滚动条时也会返回鼠标离开。我怎样才能防止这种情况? 请指教。
我正在使用此代码 `addEvent(document, "mouseleave", function(e) {
e = e ? e : window.event;
var from = e.relatedTarget || e.toElement;
jQuery(document).mouseleave(function(){
if (!from || from.nodeName == "HTML") {
$(".tso_popup_wrapper")
.animate({"width":"400px","height":"200px"},100)
.animate({"right":"100px", "top":"107px"},500)
.animate({"width":"1000px", "height":"700px"},1)
.animate({"right":"-100px", "top":"107px"},1)
.animate({"width":"1350px", "height":"700px"},1)
.animate({"right":"-298px", "top":"107px"},250);
$('.navigation-all').slideDown(300);
console.log('out');
}
});
`
【问题讨论】:
-
我不相信这是可能的;谷歌浏览器似乎将滚动条视为
document和window的“外部”。 -
对不起,因为一个人,我不得不删除我的答案。要回答您的问题,@Atul 您可以使用
element.width - element.scrollWidth。还不确定,但试一试!
标签: javascript jquery