由滚动条触发的jquery mouseleave文档 [英] Jquery mouseleave document triggered by scrollbar

查看:152
本文介绍了由滚动条触发的jquery mouseleave文档的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  $(document).ready(function(){
$(document).mouseleave(function(){
$('#desktop-subscribe- modal')。modal('show');
});
});

我试图在鼠标离开文档窗口时触发一个函数。上面的代码在Firefox中可以正常工作,但在Chrome浏览器中,当鼠标悬停在页面滚动条上时,它会被触发。



有没有办法从mouseleave函数中排除滚动条? >解决方案

好的,当mouseleave被触发时,通过检查鼠标位置来解决这个问题。当鼠标悬停在视口上方时,我只需要触发它,所以我只需检查垂直位置是否是< 0。

  $(document).ready(function(){
$(document).mouseleave(function e){

//如果(e.clientY <0){
$('#desktop-subscribe-modal')。检查鼠标在视口
之上。 ('show');
}

});
});


$(document).ready(function(){
    $(document).mouseleave(function(){
        $('#desktop-subscribe-modal').modal('show');
    });
});

I am trying to trigger a function when the mouse leaves the document window. The above code works fine in Firefox but in Chrome it is triggered when hovering over the page scrollbar.

Is there a way to exclude the scrollbar from the mouseleave function?

解决方案

Ok, I got around this issue by checking the mouse position when mouseleave is triggered. I only really need it to trigger when the mouse hovers above the viewport so I just check if the vertical position is < 0.

$(document).ready(function(){
    $(document).mouseleave(function(e){

        //Check mouse is above the viewport
        if(e.clientY < 0){
            $('#desktop-subscribe-modal').modal('show');    
        }

    });
});

这篇关于由滚动条触发的jquery mouseleave文档的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆