侦听鼠标事件…div的overflow:scroll滚动条除外? [英] listen for mouse events … except a div's overflow:scroll scrollbar?

查看:144
本文介绍了侦听鼠标事件…div的overflow:scroll滚动条除外?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

关于如何在$(document) 上监听div的任何建议

div的溢出:滚动滚动条?

我不确定滚动条是哪个元素以便引用它...

解决方案

您可以使用以下方法自己检查目标:

$(document).on('mousedown', function(e) {
    console.log(e.target);
});

FIDDLE

滚动条不是真正的元素,单击处理程序将不起作用,但似乎触发了mousedown,但只会为您提供滚动条所属的元素.

要排除仅滚动条,我猜您将不得不弄清它的大小,然后检查mousedown上的鼠标位置以查看其是否在滚动条区域内.

Any suggestions for how to listen for mousedown on $(document) except a div's overflow:scroll scrollbar?

I am not sure what element the scrollbar is in order to refer to it...

解决方案

You can check the target yourself with :

$(document).on('mousedown', function(e) {
    console.log(e.target);
});

FIDDLE

The scrollbar is'nt really an element, and click handlers won't work, but it seems mousedown is fired, but will just give you the element the scrollbar belongs to.

To exclude just the scrollbar I'm guessing you will have to figure out it's size, and then check the mouse position on mousedown to see if it's within the scrollbar area.

这篇关于侦听鼠标事件…div的overflow:scroll滚动条除外?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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