Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to detect mouseup on a scrollbar? (or "scrollEnd" event)

Anyone have any idea how to detect a mouseup event on a scrollbar? It works in FF, but not in Chrome or IE9.

I set up a quick demo: http://jsfiddle.net/2EE3P/

The overall idea is that I want to detect a scrollEnd event. There is obviously no such thing so I was going with a combination of mouseUp and timers, but mouseUp isn't firing in most browsers! The div contains a grid of items so when the user stops scrolling I want to adjust the scroll position to the nearest point that makes sense, e.g. the edge of the nearest cell. I don't, however, want to automatically adjust the position if they're in the middle of scrolling.

I'll also happily accept any answer that gives me the equivalent of scrollEnd

like image 537
Nobody Avatar asked May 12 '11 01:05

Nobody


1 Answers

found a solution that works without timers but only if you are scrolling the complete window.

switch(event.type){
            case 'mousedown':
                _btnDown = true;
                //THIS IS ONLY CAUSE MOUSEUP ON SCROLLBAR IS BUGGY
                $(document).bind('mousemove',function(event){
                    if(event.pageX < ($(window).width() - 30)){
                    //mouse is off scrollbar
                    $(this).unbind(event);
                    $(this).trigger('mouseup');
                }
               });
            break:
            case 'mouseup':
                //do whatever
                _btnDown = false;
            break;
}

pretty dirty .. but works.

like image 154
Quarkus Avatar answered Oct 29 '22 14:10

Quarkus