Listen for mouse events ... other than div overflow: scrollbar scrollbar?

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

I'm not sure which element has a scroll bar to reference it ...

+2
source share
2 answers

You can check the goal yourself:

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

Fiddle

Scrollbar is'nt really an element, and click handlers will not work, but it seems that mousedown has been fired, but will just give you the element that owns the scroll bar.

To exclude only the scrollbar, I assume that you will need to figure out its size and then check the mouse position on mousedown to see if it is in the scrollbar area.

+2
source
 <div class='scrollHolder' style='overflow:scroll;'> <div class='scrollContent'> </div> </div> $(document).on( "mousedown", function( event ) { var onScrollbar = false; if (event.target.className == "scrollHolder") { var s_c = $(event.target).children(".scrollContent"); if (event.pageX-s_c.offset().left > s_c.innerWidth()) { onScrollbar = true; } } }); 
0
source

All Articles