Search code examples
javascripthtmldomprototypejs

capturing click events on web-browser scrollbars


is it possible to capture a click event on a scrollbar? I have some code where i am observing the click and mousedown events on the document. However, it seems that when I click on the scrollbar, the event is not captured. This leads me to believe that the scrollbars aren't really part of the document. (Assumption :-)) Is this a correct assumption? What is the right way to do this so that the behaviour is consistent across all major browsers?

sample code

document.observe('click', function(evt){
    //do something
    //blah blah blah
});

Thanks


Solution

  • Correct. The closest you can get is the scroll event. It'll work on every element that has a scrollbar, and it will fire on both mouse scroll with scroll bar, scroll wheel, arrow keys, page up/down, etc. Here's a brief jQuery example.

    jQuery(document).scroll(function () {
        console.log("foo")
    });
    

    That's the best suggestion I can give you - I can't imagine any other uses for a scroll bar click event.