jedierikb
jedierikb

Reputation: 13109

listen for mouse events … except a div's overflow:scroll scrollbar?

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...

Upvotes: 2

Views: 2334

Answers (2)

jedierikb
jedierikb

Reputation: 13109

<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;
        }
    }
});

Upvotes: 0

adeneo
adeneo

Reputation: 318372

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.

Upvotes: 2

Related Questions