Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/409.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在javascript中检查鼠标下降事件不在滚动条上_Javascript - Fatal编程技术网

如何在javascript中检查鼠标下降事件不在滚动条上

如何在javascript中检查鼠标下降事件不在滚动条上,javascript,Javascript,这是我的代码: // Close the bubble when we click on the screen. document.addEventListener('mousedown', function (e) { // if ain't right click if(e.button != 2){ // hide setTimeout("bubbleDOM.style.visibility = 'hidden';", 500); } }, false); 我的问题是,当

这是我的代码:

// Close the bubble when we click on the screen.
document.addEventListener('mousedown', function (e) {
// if ain't right click
if(e.button != 2){
    // hide
    setTimeout("bubbleDOM.style.visibility = 'hidden';", 500);
}
}, false);
我的问题是,当用户尝试使用浏览器滚动条滚动时
设置超时生效。如何检查鼠标向下是否不在滚动条中?

确保按钮位于左侧,并确保它不是冒泡事件,而不仅仅是在按钮不正确时。我建议在setTimeout中也使用一个函数,因此:


但当我点击滚动条时,气泡却隐藏了起来
// Close the bubble when we click on the screen.
document.body.addEventListener('mousedown', function(e) {
    // If it's a left click and the target is the current target
    if(e.button === 1 && e.target === e.currentTarget) {
        // hide
        setTimeout(function() {
            bubbleDOM.style.visibility = 'hidden';
        }, 500);
    }
}, false);